Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

Nginx Reverse Proxy returns 404 for PHP

I am running an Nginx server and several services in jails. I have two TLDs, one old and one new. For the new TLD I have added a new jail with a new service (wordpress). I added a new server block to my reverse proxy. Accessed locally, bypassing the reverse proxy, wordpress works fine. All PHP executes correctly.

However, accessed through the reverse proxy, using the new TLD, any attempt to navigate to a .php file returns a 404 error. Note that the site itself is working and php is properly executing; the issue only arises if you try to navigate to a .php directly. 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.

These are the server blocks from my 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;
        }
    }
question from:https://stackoverflow.com/questions/65866393/nginx-reverse-proxy-returns-404-for-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I fixed this by commenting out the "pass php to fastcgi" which was apparently redundant.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...