upstream tomcat{
server ip:8080;
}
server {
listen 80;
server_name www.xxxxx.cn;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcat;
proxy_redirect off;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
nginx监听http80端口,代理到tomcat服务器
upstream可以实现负载均衡
upstream tomcat{
server ip:8080 weight=1;
server ip:8090 weight=2;
}
upstream server主要配置如下:
- IP地址和端口: 配置上有服务器的ip和端口
- 权重: weight用来配置权重,默认都是1,权重越高分配给这台服务器的请求越多,根据服务器的实际处理能力来分配权重