Nginx,默认服务器块无法看到php文件 - 但子域可以

时间:2016-03-16 01:44:56

标签: php nginx server block

我对Nginx不太满意,所以我非常感谢这里的一些帮助。

现在我的问题是,我的默认服务器阻止domain.com,拒绝访问所有php个文件。

www.domain.com/index.php我显示正确的403 Forbidden页面。

但如果我前往www.SomeRandomSubDomain.domain.com/index.php,我可以看到文件就好了。 我没有任何其他服务器块。我在下面的第一行中错过了某种标记吗?

location ~ \.php$ {
            deny all;
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in
            # php.ini
            # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            #include fastcgi_params;
            include fastcgi.conf;
    }

如果您需要任何其他信息以便进一步帮助我,请告诉我,这让我陷入了混乱的世界,我对Google没有幸运。

以下是完整文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name EXAMPLE.com www.EXAMPLE.com;
    root /var/www/html;
    index index.html index.php index.htm;
    location / {
            try_files $uri $uri/ $uri.html $uri.php?$query_string;
            # Uncomment to enable naxsi on this location include
            # /etc/nginx/naxsi.rules
            }
    location ~ .(css|img)/(.+)$ {
    try_files $uri $uri/ /$1/$2;
    }

    error_page 404 403 /404.php;

    location ~ \.php$ {
            deny all;
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in
            # php.ini
            # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            #include fastcgi_params;
            include fastcgi.conf;
     }
 }

1 个答案:

答案 0 :(得分:1)

尝试从php配置中删除deny all;