Random Nginx Upstream Timeout Error To Proxy

Viewed 13

I can't seem to figure this error out or how to debug it. Randomly on my NginX PHP-FPM Setup, my server stops acceting POST, PUT, and DELETE request. But it still will accept GET request, so people can browse the website. An example of the error message is here:

2022/09/06 20:57:44 [warn] 52#52: *20475 upstream server temporarily disabled while connecting to upstream, client: 10.x.x.x, server: example.com, request: "POST /api/accounts/login HTTP/1.1", upstream: "https://52.xxx.xxx.xx:443//accounts/login", host: "www.example.com", referrer: "https://www.example.com/login"

To fix the issue I just do a restart of nginx and problem solved. Now I noticed the POST is to:

POST /api/accounts/login

and the Upstream is to

https://xxx.xxx.xxx.xx:443//accounts/login

The /api route POST request, and it seems that Nginx is removing the /api for some reason when forwarding to the proxy. My Nginx configuration is this:

server {
    listen          80;
    listen          [::]:80;

    server_name .example.com www.example.com _ default_server;

    if ($http_x_forwarded_proto = 'http'){
        return 301 https://$host$request_uri;
    }
    
    location / {
        root    /var/www/public_html/;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?rt=$uri&$args;
    }

    location /api {
        proxy_pass_header  Set-Cookie;
        proxy_pass_header  P3P;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Fowarded-Host $host;
        proxy_pass https://api.example.com/;
        proxy_connect_timeout 5s;
    }

}

Why does it appear that Nginx is randomly removing the /api and why is restarting nginx fixing this issue?

0 Answers
Related