简体   繁体   中英

NGINX proxy_pass Second Location Block 504 Gateway Time-Out

On a server, I have 2 containers, the frontend running on port 8092 and the backend on port 3011. In a browser, I can see the frontend, but all the backend calls are getting a 504 Gateway Time-out. The frontend is an angular app, and the backend is an express nodejs app.

the backend endpoints are calling https://test.example.com/api/some-path If I go to https://xxx.domain.local:3011/api/some-path I get a response.

server {
    listen 443 ssl;
    server_name test.example.com;

    ssl_certificate /etc/ssl/certs/example.crt;
    ssl_certificate_key /etc/ssl/private/web.key;

    location / {
        proxy_pass http://xxx.domain.local:8092;
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
    }

    location /api {
        proxy_pass https://xxx.domain.local:3011;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

504 Gateway Time-out means the NGINX proxy didn't get an answer from the container within a specified timespan.

Make sure that your backend container is running and the correct port is used and exposed.

Also make sure you are using http and not https if your container doesn't have a ssl certificate.

location /api {
        proxy_pass http://xxx.domain.local:3011;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM