nginx下载:http://nginx.org/en/download.html
需要依赖包,pcre (重定向rewrite功能支持), openssl(https功能支持)
1.tar –xzvf nginx1.10-tar.gz
2.进入nginx1.10目录执行:
./configurate–help查看参数信息
./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-pcre=/usr/local/pcre-8.38/ --with-http_image_filter_module --without-http_gzip_module --add-module=/usr/local/fastdfs-nginx-module/src --with-http_ssl_module
例:
./configure--prefix=/mnt/nginx --with-http_stub_status_module --with-pcre=/mnt/pcre-8.38/--without-http_gzip_module --with-http_ssl_module
--with-http_ssl_module 支持https时需要使用的模块,可以通过 —with-openssl指定openssl位置,不指定则使用系统默认。
--perfix:配置编译,安装目录
--with-ipv6 加上支持ipv6协议
--with-http_stub_status_module : 查看监控http请求连接状态的模块,
location /nginx_status {
stub_status on;
access_log off;
}
--with-openssl : 指定openssl安装位置
--with-http_image_filter_module:安装imagefilter模块,以后可以提供图片缩略图。
--without-http_gzip_module:不适用gzip模块。
--add-module=/usr/local/fastdfs-nginx-module/src: 添加fastdfs模块支持fastdfs系统
3.make编译,然后makeinstall 安装即可。
4.进入usr/local/nginx/sbin 命令:./nginx启动即可。
5.按照需要配置usr/local/nginx/conf/nginx.conf文件。
6.例子: 如要负载到tomcat ,修改nginx.conf添加如下:
location/ {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhostHi;
}
upstream localhostHi {
server localhost:8080 weight=10;
#server localhost:8081 weight=10;
}
红色部分的域名必须一致,是负载域名。
完成后重启nginx,直接访问ip即可,不需要加8080端口了,因为nginx默认监听在80端口,浏览器访问默认是80端口。
重新加载配置文件: ./nginx –s reload
注意: nginx处理response code > 300的错误时, 需要启用:proxy_intercept_errors on; 该配置默认关闭,
可用于:http, server, location内