Score:0

nginx how to handle POST requests in 404 handler?

in flag

in my /etc/nginx/sites-enabled/devdb.easy-ads.com I have:

server {
        root /srv/http/devdb.easy-ads.com/www;
        index index.html index.htm index.nginx-debian.html index.php;
        server_name devdb.easy-ads.com;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }


        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        }
        error_page 404 = /index.php;

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/devdb.easy-ads.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/devdb.easy-ads.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

}

and this works fine for non-404 uris, and it works fine for GET requests regardless of it being 404 or not, but all 404 POST requests are converted to GET requests before being sent off to index.php, how do i stop that? on the php-side, $_POST is an empty array even when it shouldn't be, and $_SERVER['REQUEST_METHOD'] erroneously contains GET ...

Score:2
in flag

... for some unknown reason,

        error_page 404 = /index.php;

forces all requests to become GET requests, but changing it to

        error_page 404 = @the404block;
        location @the404block {
                try_files $uri $uri/ /index.php$is_args$args;
        }

fixes the problem.

This is because the designers of nginx had ingested too much vodka during the design of nginx.

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.