原狀況如下:
訪問: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; } }