Ubuntu下安装Nginx

1.安装PCRE库
$ tar -zxvf pcre-8.39.tar.gz
$ cd pcre-8.39
$ ./configure --prefix=/usr/local/pcre
$ make
$ make install

2.安装zlib库
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure --prefix=/usr/local/zlib 
$ make
$ make install

3.安装ssl
$ tar -zxvf openssl-1.0.1j.tar.gz
$ cd openssl-1.0.1j/
$ ./config  --prefix=/usr/local/ssl
$ make
$ make install

4.安装nginx
$ tar -zxvf nginx-1.8.0.tar.gz
$ cd nginx-1.8.0  
$ ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39/ --with-zlib=../zlib-1.2.11/  --with-openssl=/usr/local/ssl
$ make
$ make install

[问题1]
make[1]: *** [/usr/local/pcre/Makefile] Error 127
–with-pcre=DIR 是设置源码目录,而不是编译安装后的目录,--with-pcre=../pcre-8.39/

[问题2]
make[2]: Entering directory `/usr/local/zlib'
make[2]: *** No rule to make target `distclean'. Stop.
make[2]: Leaving directory `/usr/local/zlib'
make[1]: *** [/usr/local/zlib/libz.a] Error 2
make[1]: Leaving directory `/home/wzh/nginx/nginx-1.8.0'
make: *** [build] Error 2
–with-zlib=DIR 是设置源码目录,而不是编译安装后的目录,--with-zlib=../zlib-1.2.11/

 


5.启动
$ /usr/local/nginx/sbin/nginx
重启:
$ /usr/local/nginx/sbin/nginx –s reload
停止:
$ /usr/local/nginx/sbin/nginx –s stop
测试配置文件是否正常:
$ /usr/local/nginx/sbin/nginx –t
强制关闭:
$ pkill nginx


以上安装方法nginx的配置文件位于

/usr/local/nginx/conf/nginx.conf

[反向代理配置]

location /cluster {
proxy_pass http://192.168.3.10:8088/cluster;
}
location /static {
proxy_pass http://192.168.3.10:8088/static;
}

[配置日志模板]
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent $request_body "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time"';

access_log /var/log/nginx/access.log main;

posted @ 2017-03-09 14:08  yshy  阅读(699)  评论(0编辑  收藏  举报