公司原有的需求是敲域名后自动跳转到index.html页面,其它的动态页面全部转发到后面tomcat处进行解析,并且浏览器的地址也添加了index.html,如:
今天公司提出一个新的需求,如:
upstream index {
server 123.159.147.369:7069 weight=20 max_fails=2 fail_timeout=30s;
ip_hash;
}
server {
listen 80;
server_name www.test.com;
root /Disk/var/www/index;
location / {
index index.html index.htm;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for;
if ( !-e $request_filename ) {
proxy_pass http://index;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /Disk/var/www/index;
expires 30d;
}
本文转自 xinsir999 51CTO博客,原文链接:http://blog.51cto.com/xinsir/1562570,如需转载请自行联系原作者