我在 Mac 上通过 Homebrew 安装了 nginx。我最近尝试添加虚拟 php 服务器。当我访问正确的文件名时,它工作正常,但在调用 try 块或应提供索引文件时出现权限错误。
#200 :
http://php-sandbox.dev/index.php
#404 :
http://php-sandbox.dev/index
http://php-sandbox.dev/
文件 index.php 存在于根 Web 目录中,并且具有 744 权限,其路径中的所有文件夹也具有 744 权限。
index 指令显然被忽略了。请参阅下面的示例和错误以及我的 nginx 配置。
nginx 的站点配置文件:server { listen 80; listen [::]:80; error_log /var/log/nginx/php-sandbox/error.log debug; rewrite_log on;
server_name php-sandbox.dev;
root /Users/sswright/repos/jswright61/php-sandbox/public;
index index.php index.html;
include drop.conf; #ignores favicons
location / {
try_files $uri $uri.php $uri/ =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}
错误日志:(/请求)
2017/04/23 09:47:15 [crit] 11149#0: *9 stat() "/Users/sswright/repos/jswright61/php-sandbox/public/" failed (13: Permission denied), client: 127.0.0.1, server: php-sandbox.dev, request: "GET / HTTP/1.1", host: "php-sandbox.dev"
2017/04/23 09:47:15 [crit] 11149#0: *9 stat() "/Users/sswright/repos/jswright61/php-sandbox/public/.php" failed (13: Permission denied), client: 127.0.0.1, server: php-sandbox.dev, request: "GET / HTTP/1.1", host: "php-sandbox.dev"
2017/04/23 09:47:15 [crit] 11149#0: *9 stat() "/Users/sswright/repos/jswright61/php-sandbox/public/" failed (13: Permission denied), client: 127.0.0.1, server: php-sandbox.dev, request: "GET / HTTP/1.1", host: "php-sandbox.dev"
try 块正在执行,但尚未尝试索引。
错误日志:(/index 请求)
2017/04/23 10:11:40 [crit] 11149#0: *12 stat() "/Users/sswright/repos/jswright61/php-sandbox/public/index" failed (13: Permission denied), client: 127.0.0.1, server: php-sandbox.dev, request: "GET /index HTTP/1.1", host: "php-sandbox.dev"
2017/04/23 10:11:40 [crit] 11149#0: *12 stat() "/Users/sswright/repos/jswright61/php-sandbox/public/index.php" failed (13: Permission denied), client: 127.0.0.1, server: php-sandbox.dev, request: "GET /index HTTP/1.1", host: "php-sandbox.dev"
2017/04/23 10:11:40 [crit] 11149#0: *12 stat() "/Users/sswright/repos/jswright61/php-sandbox/public/index" failed (13: Permission denied), client: 127.0.0.1, server: php-sandbox.dev, request: "GET /index HTTP/1.1", host: "php-sandbox.dev"
这里正在寻找 index.php,但出现权限错误。当请求 /index.php 时,页面可以正常加载。