繁体   English   中英

NGINX 只执行“index.php”而不执行任何其他“*.php”文件

[英]NGINX only executing “index.php” but not any other “*.php” files

我正在尝试设置一个 CMS 来运行它的安装。 安装文件是一个安装文件夹和一个名为“setup.php”的文件。 如果我在“example.com/setup.php”访问我的网站,它会尝试下载文件,但如果我将“setup.php”重命名为“index.php”并导航到“example.com/index.php”或只是“example.com”,它执行 php 文件。

我的站点的 nginx 配置是这样的:

server {
    root /var/www/example.com;
    index  index.php index.html index.htm;
    server_name  example.com;

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / { try_files $uri $uri/ /index.php?$query_string; }

    # Pass the PHP scripts to FastCGI server
    location ~ ^/index.php {
        # Write your FPM configuration here
        include snippets/fastcgi-php.conf;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php-fpm.sock;
        #fastcgi_index index.php;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #include fastcgi_params;
    }

    # Whitelist
    ## Let TastyIgniter handle if static file does not exists
    location ~ ^/favicon\.ico { try_files $uri /index.php; }
    location ~ ^/sitemap\.xml { try_files $uri /index.php; }
    location ~ ^/robots\.txt { try_files $uri /index.php; }
    location ~ ^/humans\.txt { try_files $uri /index.php; }

    ## Let nginx return 404 if static file does not exists
    location ~ ^/assets/media { try_files $uri 404; }
    location ~ ^/storage/temp/public { try_files $uri 404; }

    location ~ ^/app/.*/assets { try_files $uri 404; }
    location ~ ^/app/.*/actions/.*/assets { try_files $uri 404; }
    location ~ ^/app/.*/dashboardwidgets/.*/assets { try_files $uri 404; }
    location ~ ^/app/.*/formwidgets/.*/assets { try_files $uri 404; }
    location ~ ^/app/.*/widgets/.*/assets { try_files $uri 404; }

    location ~ ^/extensions/.*/.*/assets { try_files $uri 404; }
    location ~ ^/extensions/.*/.*/actions/.*/assets { try_files $uri 404; }
    location ~ ^/extensions/.*/.*/dashboardwidgets/.*/assets { try_files $uri 404; }
    location ~ ^/extensions/.*/.*/formwidgets/.*/assets { try_files $uri 404; }
    location ~ ^/extensions/.*/.*/widgets/.*/assets { try_files $uri 404; }

    location ~ ^/themes/.*/assets { try_files $uri 404; }

}


server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;
    server_name  example.com;
    return 404; # managed by Certbot


}

出于安全原因,我在发布之前更改了配置中的 web 地址。 我非常困惑为什么这不起作用,好像 index.php 执行,all.php 文件应该。 任何帮助弄清楚这一点将不胜感激。

我是个白痴,度过了漫长的一天。

location ~ ^/index.php {

应该

location ~ /.php {

暂无
暂无

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

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