nginx+tomcat 反向代理 负载均衡配置
1、nginx的安装和配置见:http://www.cnblogs.com/ll409546297/p/6795362.html
2、tomcat部署项目到对应的服务器上面并启动,不详解
3、在nginx中配置nginx.conf文件:
user nobody; worker_processes 4; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream tomcat_client { #针对于8080端口实现 ip_hash; server localhost:8080; #如果存在多个部署,写入地址和端口即可 } server { listen 80; server_name localhost; #本地访问名称可以修改,针对于外网可以写成域名 #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat_client; proxy_redirect default; #设置代理 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
4、启动nginx就可以访问自己的项目