Nginx 錯誤日誌顯示奇怪的結果

Nginx 錯誤日誌顯示奇怪的結果

簡而言之,這是我的 Nginx 設定:

...

server {
    listen   80;
    server_name whatever;
    root /var/www/;

    location /api/1.0 {
        ...
        `proxy_pass http://localhost:8000/;
    }

    location /api/2.0 {
        ...
        proxy_pass http://localhost:8080/;
    }

    location / {
        root /var/www/static/;
        default_type text/html;
        try_files  $uri $uri/index.html index.html;
    }
}

如果我現在轉到localhost,並附加一個與靜態文件中的任何內容都不對應的隨機名稱,或者與兩個應用程式中的任何一個(例如http://localhost/whatever)中的任何內容都不對應的隨機名稱,我的日誌中會出現一個奇怪的錯誤:

2013/09/14 20:58:20 [錯誤] 28731#0: *2 open()“/var/wwwindex.html”失敗(2:沒有這樣的檔案或目錄),客戶端:127.0.0.1,伺服器:ec2 -54-234-175-21.compute-1.amazonaws.com,請求:“GET /whatever HTTP/1.1”,主機:“localhost”

我想這一定反映出我缺乏理解,因為我真的不知道為什麼 nginx 試圖訪問“/var/wwwindex.html”。請注意,我不希望此請求成功,我只是希望它以我理解的方式失敗。究竟發生了什麼事?感謝您的想法,提前致謝!

答案1

try_files以 結尾index.html,它被附加到(並且的root尾隨被忽略)。添加一個到它。/root/

        try_files  $uri $uri/index.html /index.html;

相關內容