0%

Nginx小记

闲来无聊看看 Nginx .

  • 操作系统: Ubuntu 14.04
  • 安装方式: Build source
  • 安装之前使用./configure 检查是否可以进行安装是否缺少模块
1
2
$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre

发生错误:

1
$ ./configure: error: the HTTP rewrite module requires the PCRE library.

解决办法:

1
$ sudo apt-get install libpcre3 libpcre3-dev

然后继续执行./configure 的命令 发现又少东西了~ 这次是 openssl

发生错误:

1
$ ./configure: error: SSL modules require the OpenSSL library.

解决办法:

1
sudo apt-get install openssl libssl-dev

然后继续./configure

OK 搞定了~ 安装吧~

1
2
$ make 
$ make install

nginx.conf 配置
需求:是想让 nginx 反向代理到本机 node express 启动的一个web 程序上但是想让在解析的时候浏览器输入 localhost8081/express 解析解析到localhost:3000上.

1
2
3
4
5
6
7
8
9
server{
listen 8081;//监听本机8081端口
server_name yun.he.he;//编辑本机 hosts 127.0.0.1解析到 yun.he.he 域名
#root /data/www/yun; //反向代理后没用
location /express/ { //解析url 中的/express
rewrite /express/(.*) /$1 break; //重写路径 $1代表前面 小括号内的内容 并且/ express 不进行转发
proxy_pass http://10.32.43.42:3000;//讲上面的地址转发到这个 url
}
}