【问题标题】:nginx php-fpm "Access Denied" on CentosCentos 上的 nginx php-fpm “拒绝访问”
【发布时间】:2015-01-13 15:13:19
【问题描述】:

我在 index.php 文件上收到“拒绝访问”。我在服务器上使用 touch 命令创建了 test.php,它正在工作。

我删除了 index.php 并使用touch 命令和 c/p index.php source new index.php 文件创建了 index.php 然后我检查了 error.log 现在问题出现在另一个 php 文件上。

一切正常,今天开始出现这个问题。此配置也可以正常工作,没有任何更改并且出现此问题。

这是我的配置文件。

/etc/nginx/conf.d/default.conf

server {

    listen 80;
    server_name X.X.X.X;
    root /var/www/domain.com;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    error_page 404 /404.html;

    location = /404.html {
        root /var/www/domain.com;
    }

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /var/www/domain.com;
    }

}

/var/www/domain.com/

drwxr-xr-x.  8 nginx nginx  4096 Nov 16 16:39 .
drwxr-xr-x.  5 nginx nginx  4096 Oct 30 20:47 ..
-rwxr-xr-x.  1 nginx nginx   146 Jun  1 18:16 CONTRIBUTING.md
drwxr-xr-x. 12 nginx nginx  4096 Oct 30 23:36 app
-rwxr-xr-x.  1 nginx nginx  2452 Jun  1 18:16 artisan
drwxr-xr-x.  2 nginx nginx  4096 Oct 30 23:36 assets
drwxr-xr-x.  2 nginx nginx  4096 Oct 30 23:36 bootstrap
-rwxr-xr-x.  1 nginx nginx   697 Jun  1 18:16 composer.json
-rwxr-xr-x.  1 nginx nginx 58540 Oct  1 00:19 composer.lock
-rwxr-xr-x.  1 nginx nginx     0 Jun  1 18:16 favicon.ico
-rwxr-xr-x.  1 nginx nginx  1580 Oct 31 00:05 index.php
drwxr-xr-x.  2 nginx nginx  4096 Oct 30 23:36 packages
-rwxr-xr-x.  1 nginx nginx   567 Jun  1 18:16 phpunit.xml
drwxr-xr-x.  2 nginx nginx  4096 Oct 30 23:55 public
-rwxr-xr-x.  1 nginx nginx  2051 Jun  1 18:16 readme.md
-rwxr-xr-x.  1 nginx nginx    24 Jun  1 18:16 robots.txt
-rwxr-xr-x.  1 nginx nginx   519 Jun  1 18:16 server.php
-rwxr-xr-x.  1 nginx nginx    41 Nov 16 16:39 test.php
drwxr-xr-x. 20 nginx nginx  4096 Oct 30 23:36 vendor

/etc/nginx/nginx.conf

user              nginx;

/etc/php-fpm.d/www.conf: 用户 = nginx 组 = nginx

/var/log/nginx/error.log

Unable to open primary script: /var/www/domain.com/index.php (Permission denied)" while reading response header from upstream, client: *, server: *, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "*"
2014/11/16 18:27:54 [error] 5070#0: *21 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0

在我删除 index.php 并使用 touch 命令创建相同的文件后:

PHP message: PHP Fatal error:  require(): Failed opening required '/var/www/domain.com/bootstrap/autoload.php'

【问题讨论】:

  • nginx.conf 的内容是什么?错误日志中有什么?在代理目标(php-fpm?)日志中? php-fpm 的用户是什么? nginx的用户是什么?
  • 使用namei 诊断权限问题。
  • 谢谢你我去试试..

标签: nginx php centos6


【解决方案1】:

感谢您的回答 - 这与我遇到的问题“拒绝访问”相同,您的解决方案使我走上了正确的道路。

请注意,您可以这样做,而不是完全禁用 SELINUX:

$ sudo setsebool -P httpd_read_user_content 1

我目前的设置是使用 CentOS 7.7、NGINX 1.17.3、PHP-FPM 7.3.9。

【讨论】:

    【解决方案2】:

    我刚刚在同一个问题上花了一整天,最终发现是 selinux 造成的。

    我没有准确搜索可能有问题的设置,只是禁用了整个设置(SELINUX=disabled in /etc/selinux/config 并重新启动),最后php-fpm 正常工作。

    【讨论】:

      猜你喜欢
      • 2014-06-16
      • 2012-11-19
      • 2016-03-26
      • 2017-03-21
      • 2015-07-13
      • 1970-01-01
      • 2017-07-14
      • 2020-04-24
      • 2020-08-25
      相关资源
      最近更新 更多