Search code examples
nginxnext.jsreverse-proxy

Next js api route nginx reverse proxy not working


I have a nextjs app behild nginx using reverse proxy. I'm unable to successfully process POST requests to /api/ 504 (Gateway Time-out)

It works perfectly when i try with a vm on a local network, but no luck with actual vps

location / {
    proxy_pass             http://127.0.0.1:3000;
    proxy_read_timeout     60;
    proxy_connect_timeout  60;
    proxy_redirect         off;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
  
  location /_next/static {
        add_header Cache-Control "public, max-age=3600, immutable";
        proxy_pass http://127.0.0.1:3000/_next/static;
  }

Solution

  • Issue was on the vps provider side. Swiched to aws and it works flawlessly. Issue was a closed smtp port on the provider side, which i was using in my post api.