簡體   English   中英

Nginx 一直在尋找 index.html

[英]Nginx keeps looking for index.html

http://localhost顯示 nginx 1.13 的 404。 當我查看容器日志時,我可以看到 nginx 沒有將請求傳遞給 php-fpm,而是在尋找 index.html。 我不明白為什么它不會將請求傳遞給 php-fpm

/etc/nginx/conf.d/default.conf

我已驗證此文件已加載。

server {
    listen   80;
    root /var/www/html/public;
    index index.php;

    charset utf-8;

    # look for local files on the container before sending the request to fpm
    location / {
        try_files $uri /index.php?$query_string;
    }

    # nothing local, let fpm handle it
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass            localhost:9000;
        fastcgi_index           index.php;
        include                 fastcgi_params;
        fastcgi_param           REQUEST_METHOD  $request_method;
        fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param           QUERY_STRING    $query_string;
        fastcgi_param           CONTENT_TYPE    $content_type;
        fastcgi_param           CONTENT_LENGTH  $content_length;
        # Httpoxy exploit (https://httpoxy.org/) fix
        fastcgi_param           HTTP_PROXY "";

        # allow larger POSTS for handling stripe payment tokens
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
   }
}

Web 容器內的進程列表:

PID   USER     TIME   COMMAND
    1 root       0:00 s6-svscan -t0 /var/run/s6/services
   33 root       0:00 s6-supervise s6-fdholderd
  170 root       0:00 s6-supervise php-fpm
  171 root       0:00 s6-supervise nginx
  173 root       0:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
  174 root       0:00 {run} /bin/sh ./run
  177 root       0:00 nginx: master process nginx -g daemon off;
  187 nginx      0:00 nginx: worker process
  192 www-data   0:00 php-fpm: pool www
  193 www-data   0:00 php-fpm: pool www
  194 root       0:00 ps -ef

容器日志

web_1    | 2017/05/13 06:13:10 [error] 187#187: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", host: "mysite.local"
web_1    | 172.19.0.1 - - [13/May/2017:06:13:10 +0000] "GET / HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"

更新根據以下一些評論刪除了對 index.htm 的所有引用

nginx使用index指令的默認值來處理 URI / (因為該目錄確實存在)。

您應該向server塊添加顯式index語句。

server {
    ...
    index index.php;
    location / {
        try_files $uri /index.php?$query_string;
    }

    # nothing local, let fpm handle it
    location ~ [^/]\.php(/|$) {
        ...
    }
}

有關更多信息,請參閱 此文檔

問題是,盡管我自己的 vhosts 配置在/etc/nginx/conf.d/default.conf ,但nginx -T (顯示 nginx 的加載配置)沒有顯示文件已被讀取。

include /etc/nginx/conf.d/*.conf; 我的nginx.conf中缺少指令。

默認情況下, /etc/nginx/conf.d/文件夾中的所有配置文件,包括您在此處的文件/etc/nginx/conf.d/default.conf ,都是從/etc/nginx/nginx.conf擴展而來的。

在此配置中,您沒有在server {}塊中指定index指令。 然后 nginx 將在/etc/nginx/nginx.conf查找默認值。

解決方案是覆蓋默認值:

server {
    listen   80;
    root /var/www/html/public;
    charset utf-8;
    index index.php index.html index.htm;
}

然后重置你的 nginx: sudo service nginx restart

然后index.php將比其余的具有更高的優先級供 nginx 查找。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM