简体   繁体   English

在Centos上使用nginx php-fpm“拒绝访问”

[英]nginx php-fpm “Access Denied” on Centos

I am getting "Access Denied" on index.php file. 我在index.php文件上收到“Access Denied”。 I created test.php by using touch command on my server and it is working. 我在我的服务器上使用touch命令创建了test.php,它正在运行。

I deleted index.php and created index.php by using touch command and c/p index.php source new index.php file and then I checked error.log now the problem is occurred on another php file. 我删除了index.php并使用touch命令和c / p index.php创建了index.php源新的index.php文件,然后我检查了error.log,现在问题发生在另一个php文件上。

Everything was working and today this problem started. 一切正常,今天这个问题就开始了。 This configuration also was working, there was no change and this problem occurred. 此配置也正常工作,没有任何更改,并且出现此问题。

Here is my config files. 这是我的配置文件。

/etc/nginx/conf.d/default.conf : /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/ : /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 : /etc/nginx/nginx.conf

user              nginx;

/etc/php-fpm.d/www.conf : user = nginx group = nginx /etc/php-fpm.d/www.conf = nginx group = nginx

/var/log/nginx/error.log : /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

After I deleted index.php and created by using touch command same file: 删除index.php并使用touch命令创建同一文件后:

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

I've just spent a whole day on the same problem, eventually finding that selinux was causing it. 我刚刚在同一个问题上度过了一整天,最终发现selinux正在引发它。

I haven't search exactly which setting might be at fault, just disabled the whole thing ( SELINUX=disabled in /etc/selinux/config and a restart) and finally php-fpm works as it should. 我没有确切地搜索哪个设置可能有问题,只是禁用了整个事情( SELINUX=disabled in /etc/selinux/config并重新启动),最后php-fpm正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM