这是我的sites-available / myServer,正确链接到sites-enabled / 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
答案 0 :(得分:0)
这里似乎有两个问题。
第一个问题是root
块缺少location ~ \.php$
指令意味着try_files $uri =404;
语句将始终以404响应失败。
404响应被重定向到/404.html
,并且从错误日志中看来,似乎没有名为/home/tyrion/saveup-compute/404.html
的文件。
如果要将HTML文件和PHP文件放在不同的目录层次结构中,则需要向root
块添加location ~ \.php$
指令,以便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;
有关详情,请参阅this document。