2017-05-13 192 views
1

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

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

我已經驗證了這個文件被加載。在Web容器內

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; 
    } 
} 

進程列表:

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所有引用

+0

錯誤消息表明這個「服務器」塊沒有處理請求。通過驗證您的意思是'nginx -T'?要麼刪除默認服務器塊,要麼給這個「server_name」。 –

+0

默認情況下它有'server_name'「',即。除非指定了'default_server',否則永遠不會使用非空的'Host'標頭獲得該塊。 – Deadooshka

回答

0

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

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

0

默認情況下,中的所有配置文件文件夾,包括您的文件在這裏/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的查找。

+0

感謝您的反饋。通過運行'docker-compose exec web cat/etc/nginx/conf.d/default.conf'來實現這個改變並驗證它在文件系統中後,我仍然看到了這個問題。 – Webnet

+0

你可以給我提供'/ etc/nginx/conf的內容嗎?d/default.conf'文件?最好在你的容器內登錄並檢查我提到的文件。因爲更改後還需要刷新nginx。 – ThangTD

+0

我已更新上述配置。在對虛擬主機進行配置更改後,我通過容器重新啓動。虛擬主機文件通過掛載提供,因此足以進行更新。 – Webnet

0

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(/|$) { 
     ... 
    } 
} 

查看this document瞭解更多。

+0

看到我更新的帖子,添加這並沒有幫助。 – Webnet