Nginx反向代理和负载均衡
采用服务器80转发8080,即外部访问时访问80端口,nginx代理tomcat和转发内部的8080端口,tomat端口是8080.重点需要在 Nginx的配置文件中配置如下红色的地方。
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream server_tomcat {
#server 10.131.156.168:8080 weight=20;
#server 10.131.156.168:9200 weight=20;
server localhost:8080 weight=20;
#server 10.131.156.169:8080 weight=80;
#server 10.131.156.170:8080 weight=100;
}
server {
listen 80;
#listen 443;
server_name server_tomcat;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://server_tomcat;
}