簡體   English   中英

PHP7 FPM和Nginx-獲取404

[英]PHP7 FPM and Nginx - Getting 404s

這是我的可用站點/ myServer,已正確鏈接到啟用站點/ myServer:

server {
    listen 80;
    server_name sub.domain.net;

    location / {
             root /home/tyrion/saveup-compute;
             index index.php index.html index.htm
             try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
         root /usr/share/nginx/www;
    }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /home/username/myServer/$fastcgi_script_name;
            include fastcgi_params;
        }
}

我進入php fpm文件,並設置660和www-data,並在目錄中將chown設置為www-data:myuser。 不過,我無法提供單個php文件。 (html很好用)。

Nginx訪問日志:

MYIP - - [15/Sep/2016:23:09:13 +0000] "GET /info.php HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"

Nginx錯誤日志:

2016/09/15 23:09:13 [error] 38415#38415: *2 open() "/home/myUser/myServer/404.html" failed (2: No such file or directory), client: 62.155.132.7, server: sub.somain.net, request: "GET /info.php HTTP/1.1", host: "sub.somain.net"

php7.0-fpm.log:

[15-Sep-2016 21:54:49] NOTICE: fpm is running, pid 35917
[15-Sep-2016 21:54:49] NOTICE: ready to handle connections
[15-Sep-2016 21:54:49] NOTICE: systemd monitor interval set to 10000ms
[15-Sep-2016 22:56:58] NOTICE: Terminating ...
[15-Sep-2016 22:56:58] NOTICE: exiting, bye-bye!
[15-Sep-2016 22:56:58] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[15-Sep-2016 22:56:58] NOTICE: fpm is running, pid 37925
[15-Sep-2016 22:56:58] NOTICE: ready to handle connections
[15-Sep-2016 22:56:58] NOTICE: systemd monitor interval set to 10000ms

這里似乎有兩個問題。

第一個問題是location ~ \\.php$塊缺少root指令,這意味着try_files $uri =404; 語句將始終失敗並返回404響應。

404響應重定向到/404.html並且從錯誤日志中重定向,似乎沒有名為/home/tyrion/saveup-compute/404.html文件。

如果將HTML文件和PHP文件放置在不同的目錄層次結構中,則需要在location ~ \\.php$塊中添加root指令,以便try_files指令起作用。

如果將HTML文件和PHP文件放在同一目錄層次結構中,則應移動root /home/tyrion/saveup-compute; 語句放入server塊,以便所有location塊都繼承相同的值。

您還應該更改SCRIPT_FILENAME的定義,以便它使用正確的root值(首先包括fastcgi_params,以避免它無提示地覆蓋您的定義):

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;

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

暫無
暫無

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

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