Nginx下载地址 http://nginx.org/
Tomcat负载均衡配置
nginx.conf配置
upstream xy { ip_hash; #session请求固定到一台服务器上面 server 192.168.0.251:8080; server 192.168.0.251:8081; server 192.168.0.251:8082; }
location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xy; #与tomcats.conf里配置的upstream同名 } 保存后重新加载配置:nginx -s reload
#所有js,css相关的静态资源文件的请求由Nginx处理 location ~.*\.(js|css)$ { root /data/www; #指定文件路径 expires 12h; #过期时间为12小时 } #所有图片等多媒体相关静态资源文件的请求由Nginx处理 location ~.*\.(html|jpg|jpeg|png|bmp|gif|ico|mp3|mid|wma|mp4|swf|flv|rar|zip|txt|doc|ppt|xls|pdf)$ { root /data/www; #指定文件路径 expires 7d; #过期时间为7天 } [root@iZ25t7h86n9Z web1]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful