简体   繁体   English

Nginx 反向代理为 PHP 返回 404

[英]Nginx Reverse Proxy returns 404 for PHP

I am running an Nginx server and several services in jails.我正在监狱中运行 Nginx 服务器和多项服务。 I have two TLDs, one old and one new.我有两个 TLD,一个旧的,一个新的。 For the new TLD I have added a new jail with a new service (wordpress).对于新的 TLD,我添加了一个带有新服务(wordpress)的新监狱。 I added a new server block to my reverse proxy.我向我的反向代理添加了一个新的服务器块。 Accessed locally, bypassing the reverse proxy, wordpress works fine.在本地访问,绕过反向代理,wordpress 工作正常。 All PHP executes correctly.所有 PHP 都能正确执行。

However, accessed through the reverse proxy, using the new TLD, any attempt to navigate to a.php file returns a 404 error.但是,使用新 TLD 通过反向代理访问时,任何尝试导航到 a.php 文件的尝试都会返回 404 错误。 Note that the site itself is working and php is properly executing;请注意,该站点本身正在运行,并且 php 正在正确执行; the issue only arises if you try to navigate to a.php directly.仅当您尝试直接导航到 a.php 时才会出现此问题。 This is problematic, for example, because you can't access the login page.例如,这是有问题的,因为您无法访问登录页面。 In fact, you can't even navigate to index.php, even though going to domain2.com itself works, domain2.com/index.php fails.实际上,您甚至无法导航到 index.php,即使转到 domain2.com 本身有效,但 domain2.com/index.php 失败。

These are the server blocks from my nginx.conf:这些是我的 nginx.conf 中的服务器块:

    #Domain2

   server  {
        server_tokens off;
        listen  80;
        server_name     www.domain2.com domain2.com;
        return 301  https://$host$request_uri;
}

    server {
        server_tokens off;
        listen       443 ssl;
        server_name  www.domain2.com domain2.com;
        ssl_certificate /usr/local/etc/letsencrypt/live/domain2.com/cert.pem;
        ssl_certificate_key /usr/local/etc/letsencrypt/live/domain2.com/privkey.pem;
        
            
        #USE SECURE PROTOCOLS  
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
        
        #DEFINE ACCESS LOG LOCATION
        access_log /var/log/nginx/access_domain2.log;
        
            
        #PASS PHP TO FASTCGI
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $request_filename;
            include        fastcgi_params;
        }

        #PROXY_SETTINGS
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        #Timeout if the real server is dead
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        # Advanced Proxy Config
        send_timeout 5m;
        proxy_read_timeout 240;
        proxy_send_timeout 240;
        proxy_connect_timeout 240;
        
        location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Proto https;
      proxy_redirect off;
      proxy_http_version 1.1;
            proxy_pass http://192.168.1.253;
        }

            
        error_page  401 403 404              /404.html;
        #redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        root   /usr/local/www/nginx-dist;
        }
    }

I fixed this by commenting out the "pass php to fastcgi" which was apparently redundant.我通过注释掉“将 php 传递给 fastcgi”来解决这个问题,这显然是多余的。

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

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