【问题标题】:NGINX only executing "index.php" but not any other "*.php" filesNGINX 只执行“index.php”而不执行任何其他“*.php”文件
【发布时间】:2021-02-09 19:28:27
【问题描述】:

我正在尝试设置一个 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


}

出于安全原因,我在发布之前更改了配置中的网址。我非常困惑为什么这不起作用,就像 index.php 执行一样,所有 .php 文件都应该执行。任何解决此问题的帮助将不胜感激。

【问题讨论】:

    标签: php nginx


    【解决方案1】:

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

    location ~ ^/index.php {
    

    应该是

    location ~ /.php {
    

    【讨论】:

      猜你喜欢
      • 2016-02-09
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 2019-08-09
      • 2017-06-05
      • 2019-07-21
      • 2011-12-30
      • 1970-01-01
      相关资源
      最近更新 更多