用403 Forbidden打开index.php

时间:2016-10-19 03:07:33

标签: php nginx

我使用nginx 1.10.1, PHP 5.4.16 (fpm-fcgi)

我的文件'位置为/usr/share/nginx/html/lab/。在此目录中,有多个.php个文件,包括index.php

如果我在此目录中放置index.html文件,我可以正确查看来自http://192.168.201.210:8024/lab/的index.html内容。但是如果我删除index.html文件,我只能获得403 Forbidden

我的php-fam效果很好,我看到很多解决方案对我不起作用:

Can't open index.php by default with nginx

https://serversforhackers.com/video/php-fpm-configuration-the-listen-directive

这是我的nginx配置文件:

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       8024; # default_server;
        # listen       [::]:8024 ipv6only=on default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {

        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {

        location ~* \.php$ {
            try_files $uri $uri/ = 404;
            include fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
            index index.php index.html;
        }
    }
}

2 个答案:

答案 0 :(得分:0)

您可以查看日志文件以获取一些信息 tail -n 50 /var/log/nginx/access.log

你知道403,php-fpm是否正确访问网络路径, 比如chmod 755 -R /usr/share/nginx/html/lab/

答案 1 :(得分:0)

最后我找到原因:我有另一个django应用程序在同一个端口监听 - 8024.如果我删除了django应用程序的配置文件或将nginx的配置文件修改为

listen       8024 default_server;

然后,我可以很好地访问index.php。但我无法再在同一个端口访问我的django应用程序。

这里有一个非常好的教程,用于在nginx中配置php:PHP FastCGI Example