原状况如下:
访问:www.test.com 敲回车后浏览器中自动跳转致: www.test.com/index.html
公司新需求如下:
访问:www.test.com 敲回车后浏览器中url不变,仍显示www.test.com,但是能访问到index.html页面。
配置如下:
#以下为负载均衡设置,与题目无关 upstream index { server 123.159.147.369:7069 weight=20 max_fails=2 fail_timeout=30s; ip_hash; } #以下为server站点设置 server { listen 80; server_name www.test.com; root /home/wwwroot/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为判断访问/目录有,匹配到该if,跳转到index配置项,即访问到index.html。 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设置,与题目无关 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /home/wwwroot/index; expires 30d; } }