Nginx Reverse Proxy Calling 504 Gateway Timeout

I use Nginx as a reverse proxy server that accepts requests and then does proxy_pass to get the actual web application from the upstream server running on port 8001.

If I go to mywebsite.com or do wget, I get 504 Gateway Timeout in 60 seconds ... However, if I download mywebsite.com:8001, the application loads as expected!

So, something does not allow nginx to communicate with the upstream server ...

It all started after my hosting company reset worked on my computer, before that there were no problems.

Here is my vhosts server server:

server { listen 80; server_name mywebsite.com; root /home/user/public_html/mywebsite.com/public; access_log /home/user/public_html/mywebsite.com/log/access.log upstreamlog; error_log /home/user/public_html/mywebsite.com/log/error.log; location / { proxy_pass http://xxx.xxx.xxx.xxx:8001; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 

And the output from my Nginx error log:

2014/06/27 13:10:58 [error] 31406 # 0: * 1 upstream timeout (110: connection timeout) when connecting to the upstream, client: xxx.xx.xxx.xxx, server: mywebsite .com, request: "GET / HTTP / 1.1", upstream: " http://xxx.xxx.xxx.xxx:8001/ ", host: "mywebsite.com"

+46
reverse-proxy nginx proxypass
Jun 27 '14 at 13:45
source share
2 answers

You can probably add a few more lines to increase the waiting period to the upstream. The examples below set a timeout of up to 300 seconds:

 proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; send_timeout 300; 
+81
Sep 19 '14 at 8:25
source share

Increasing the timeout is unlikely to solve your problem, as, as you say, the actual target web server responds perfectly.

I had the same problem and found that this is because you are not using keep-alive in the connection. I cannot answer the question why this is so, but when clearing the connection header, I solved this problem and the request was proxied just fine:

 server { location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_pass http://localhost:5000; } } 

Take a look at these posts, which explain this in more detail: nginx close upstream connection after request Clear heading header http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive

+16
Apr 13 '16 at 5:13
source share



All Articles