nginx配置 首頁不顯示 index.html首頁是顯示域名


原狀況如下:

    訪問: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;

        }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM