sudo ls -l /path/to/web/root
sudo ls -l /path/to/web/file
确保文件和目录的拥有者与用户组是Nginx服务器进程用户和组,同时确保权限设置为755和655。
在Nginx配置文件的server段中输入以下代码:
location ~ .php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
确保fastcgi_pass所指向的文件与PHP-FPM中的监听地址相同。
getenforce
如果当前状态是enforcing,说明SELinux不允许Nginx服务器进程访问目标目录,可以通过以下命令关闭SELinux:
sudo setenforce 0
如果仍想使用SELinux,则需要为目标目录设置安全上下文。可以通过以下命令查询当前设置:
ls -Z /path/to/web/root
根据查询结果,通过以下命令为目标目录设置安全上下文:
sudo chcon -Rv --type=httpd_sys_content_t /path/to/web/root
可以输入以下命令查看