# NGINX Reverse Proxy 504 Gateway Time-out

**URL:** <https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259>\
**Category:** Questions / Help\
**Created:** [March 3, 2022, 8:22pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259 "2022-03-03T20:22:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jacob/32/2210_2.png) [@jacob](https://community.fly.io/u/jacob)\
**Post date:** [March 3, 2022, 8:22pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/1 "2022-03-03T20:22:10Z")

</div>

Hello there,

I am have a few issues with the reverse proxy NGINX setup for generating certs using docker from the sample config created by @kurt [here](https://github.com/fly-apps/nginx)

It seems that the proxy container times out with a 504 Gateway Time-out error during multiple instances, like making a request to the stripe API or possibly due to a redirect. I’ve tried to increase the proxy\_connect\_timeout value to prevent this but it doesn’t seem to have worked after restart.

The access and error logs doesn’t seem to be available when I ssh into the container.

---

<div class="post-metadata">

**Author:** ![catflydotio](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/catflydotio/32/14559_2.png) [@catflydotio](https://community.fly.io/u/catflydotio)\
**Post date:** [March 3, 2022, 8:46pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/2 "2022-03-03T20:46:52Z")

</div>

Hi @jacob, sorry I don’t have much to offer here, except that I see that the `fly-apps/nginx` repo is on a list of not-recently-updated example apps I’m slowly archiving. It’s possible the reason for your trouble is that Things Have Changed since this was last updated.

---

<div class="post-metadata">

**Author:** ![jacob](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jacob/32/2210_2.png) [@jacob](https://community.fly.io/u/jacob)\
**Post date:** [March 3, 2022, 9:10pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/3 "2022-03-03T21:10:26Z")

</div>

Thank you for the update, we are currently using this setup to assign certs and previously used the javascript apps that are no longer supported in terms of updates since it’s read only now. It’s critical to try to fix this since we cannot signup new customers due to this issue.

It also seems to lose the site if www. is removed from the url after a site is loaded with it: [www.homebasestorefront.com](http://www.homebasestorefront.com) then [homebasestorefront.com](http://homebasestorefront.com) is one such example.

Only difference is in the nginx.conf with the origin\_url being https://(our ip) and commenting out:

```
    set $origin_host_header example.org;

```

and uncommenting:

```
    set $origin_host_header $http_host;
```

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [March 3, 2022, 9:12pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/4 "2022-03-03T21:12:07Z")

</div>

Is this running in Virginia by chance? AWS is having networking issues that affect connectivity from Fly apps in Virginia. These could be the cause of 504s. If you _are_ running in `iad`, the quick fix is `fly region remove iad`.

---

<div class="post-metadata">

**Author:** ![jacob](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jacob/32/2210_2.png) [@jacob](https://community.fly.io/u/jacob)\
**Post date:** [March 3, 2022, 9:24pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/5 "2022-03-03T21:24:44Z")

</div>

All of our cloud services are now on Azure but this server is Virginia as well.

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [March 3, 2022, 9:30pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/6 "2022-03-03T21:30:40Z")

</div>

Ah, probably not related then.

How long should the requests take that are timing out? And is the 504 coming from nginx or from our proxy? If it’s nginx, you’ll see a little thing on the footer saying nginx generated the error (by default).

504s mean there’s a timeout issue, yes. Probably not a connect timeout, you’ll need to tweak the read timeout setting: [Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout)

Our proxy has a 60s read timeout. I’d suggest setting the nginx read timeout to, like, 45 seconds. That might help.

---

<div class="post-metadata">

**Author:** ![jacob](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jacob/32/2210_2.png) [@jacob](https://community.fly.io/u/jacob)\
**Post date:** [March 3, 2022, 9:45pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/7 "2022-03-03T21:45:35Z")

</div>

It’s an nginx error, gives the version number 1.21.5 and everything. I’ve increased these previously beyond the original 30000ms for proxy\_read\_timeout. It feels like the gateway timeout error happens pretty quickly and the requests usually do not take that long.

Does it need to be restarted for these to take affect? If so, I assume I would have to redeploy the local docker setup as it resets the values.

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [March 3, 2022, 9:48pm UTC](https://community.fly.io/t/nginx-reverse-proxy-504-gateway-time-out/4259/8 "2022-03-03T21:48:39Z")

</div>

Oh yes, you’ll definitely need to update the config and redeploy to get it to take. Editing the file on the running VM won’t have any affect, if that’s what you’re doing.

But that 30s proxy read timeout seems like it should be enough. You may be able to see exactly what it thinks is happening with `fly logs`.
