一,安装依赖
1,gcc
yum install gcc-c++
2,PCRE
yum install -y pcre pcre-devel
3,zlib
yum install -y zlib zlib-devel
4,openssl
yum install -y openssl openssl-devel
二,编译及安装
1,将nginx包解压到/root/test/nginx目录
2,编译,运行configure
./configure
3,输入make
4,make install
5,cd /usr/local/nginx
6,启动 ./nginx
注:启动之前把80端口防火墙开放
80端口放行
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
三,关闭nginx
关闭命令,相当于kill
./nginx -s stop
退出命令
./nginx -s quit
四,动态加载配置文件与配置集群
./nginx -s reload
可以不关闭nginx的情况下更新配置文件
配置nginx的服务集群列表
upstream server_list{
server localhost:8080;
server localhost:8081;
}
server {
listen 80;
server_name localhost;
location / {
root html;
proxy_pass http://server_list;
index index.html index.htm;
}
}
五,反向代理400错误
错误:使用Nginx的反向代理访问tomcat时400错误。
upstream配置:
upstream java_test{
server 127.0.0.1:8080;
}
原因:nginx中upstream后面的名称不能使用下滑线,Nginx不能识别。
解决:将java_test改成java- test后问题解决。