nginx提示錯誤 Access denied.?
[error] 18831#0: *1 FastCGI sent in stderr: "Unable to open primary script: /var/www/testmysql.php (Permission denied)" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /testmysql.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost", referrer: "http://localhost/"
這是 日誌
http://localhost/indexs.php 時 可以 顯示但是 http://localhost/testmysql.php顯示 Access denied.
兩個要點 1. vi /etc/php-fpm.d/www.conf #編輯
user = nginx #修改用戶為nginx
group = nginx #修改組為nginxservice php-fpm restart2.chown nginx.nginx /usr/share/nginx/html/ -R #設置目錄所有者chmod 700 /usr/share/nginx/html/ -R #設置目錄許可權
試試看不是提示你是access denied了么? 初步判斷php5-fpm無權讀取這個文件。chmod
SELinux will cause this error on CentOS/RHEL 7+ by default
To test if SELinux is the source of your woes, do
setenforce 0
... and see if everything works. If that fixed it, you can leave SELinux off (weak, youre better than that), or you can turn it back on with
setenforce 1
... and then properly fix the issue.
If you do
tail -f /var/log/audit/audit.log
... youll see the SELinux issue. In my case, it was denying PHP-FPM access to web files. You can run the following directives to fix it:
setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_network_connect 1
This actually didnt fix it for me at first, but then restoring SELinux context did it
restorecon -R -v /var/www
Hope that helps.
謝謝匿名用戶的回答,找了好久的答案
推薦閱讀: