Score:0

how to stop nginx 302 error

my flag

I have a site with Ubuntu 20.04, php 8.1, and nginx 1.23.1. If I restart nginx and php-fpm I can login, browse the site, and everything works. If I wait a certain amount of time with no activity on the site (10-15 minutes?), I start getting 302 Found errors no matter what page I try to go to. If I restart nginx and php-fpm again, everything starts working again. I can't figure out what's causing this. Here is the nginx config file for the site:

server {
        listen 1443 ssl;
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" ;
        server_name my_site;
        root /var/www/my_site/htdocs;
        index index.php index.html;

        access_log  /var/log/nginx/my_site.access.log;
        error_log   /var/log/nginx/my_site.error.log;

        ssl_certificate /etc/nginx/ssl/all.my_site.com.crt;

        ssl_certificate_key /etc/nginx/ssl/all.my_site.com.key;

   
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;
        ssl_protocols TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK';
        ssl_prefer_server_ciphers on;

        proxy_buffer_size   128k;
        proxy_buffers   4 256k;
        proxy_busy_buffers_size   256k;

        
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;

        location / {

                try_files $uri =404;

                # pass PHP scripts to FastCGI server
                
                location ~ \.php$ {
                        include snippets/fastcgi-php.conf;

                        fastcgi_pass unix:/run/php/php8.1-fpm.sock;

                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
            
                        fastcgi_param ALL_FILES_PATH /var/www/my_site;
                        fastcgi_param LOCAL_FILES_PATH /var/www/my_site;
                        fastcgi_param SHARED_FILES_PATH /var/www/my_site-web-8.1;

                        fastcgi_read_timeout 604800;
                        include /etc/nginx/fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                }

        }

}

EDIT: It appears that this 302 error is only happening with PHP files. I put a basic html file in and it loads with a 200 response code.

aceraven777 avatar
pg flag
Did you check the error logs?
my flag
@aceraven777 Yes, nothing appears in the error log. The access log shows a hit, but with the 302 return code.
drookie avatar
za flag
302 doesn't indicate the error. It's a successful code.
my flag
But why is it not returning 200? It's like some timeout is reached and everything changes from 200 to 302. But I don't see anything like that in the config file.
in flag
302 is a redirect. It's most probably generated by your php files and not by ngnix.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.