# Nginx rate limiting outside of container - any tips?

**URL:** https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711
**Category:** Self-hosting
**Created:** [9 maart 2020 om 16:32 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711 "2020-03-09T16:32:28Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [9 maart 2020 om 16:32 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/1 "2020-03-09T16:32:29Z")

</div>

Can anybody please share his working configuration for rate limiting nginx outside of docker container (setup with discourse on the socket)? Thanks..

I seem to be unable to tune it properly and still limiting valid traffic.

> [@Add an offline page to display when Discourse is rebuilding or starting up](https://meta.discourse.org/t/adding-an-offline-page-when-rebuilding/45238/72):
>
> It should be noted that running an nginx proxy in front of Discourse as described here will result in the rate limit, which is by default configured in Discourse Docker to apply for requests for all users. The [rate limit template](https://github.com/discourse/discourse_docker/blob/ceffc4433e1bd6fcbd101f2427e17232fc99ab14/templates/web.ratelimited.template.yml) templates/web.ratelimited.template.yml should be removed from the docker config and the rate limit should then be configured in the outer nginx instance instead.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [10 maart 2020 om 01:22 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/2 "2020-03-10T01:22:38Z")

</div>

> [@Overgrow](#):
>
> I seem to be unable to tune it properly and still limiting valid traffic.

Do you mean that traffic is getting limited when it shouldn’t be or that you are not limiting traffic when it should be?

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [10 maart 2020 om 13:09 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/3 "2020-03-10T13:09:13Z")

</div>

> [@pfaffman](#):
>
> Do you mean that traffic is getting limited when it shouldn’t be

Exactly.. for start I have used template from the inside of the container and moved it outside. I don’t know if there is some recommended config for rate limiting outer nginx.  
Emojis and avatars seem to be suitable for different limits than the rest of traffic.

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [20 maart 2020 om 16:31 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/4 "2020-03-20T16:31:26Z")

</div>

Bump.. Really nobody is willing to share his tips for working rate limits for outer nginx? Thanks in advance!

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [20 maart 2020 om 16:45 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/5 "2020-03-20T16:45:24Z")

</div>

Please don’t bump topics. If someone had an answer for you I’m sure they would have volunteered it.

Assuming that you have followed the other guides here on meta, and [nginx is correctly configured](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247) to pass client IPs into the container, is this actually a discourse problem?

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [20 maart 2020 om 16:47 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/6 "2020-03-20T16:47:47Z")

</div>

a) AFAIK nginx outside of container is recommended  
b) It should be tailor-made to what discourse requires

So, yes I see it as discourse related problem.

Is this really true and recommended practice?

> The [rate limit template](https://github.com/discourse/discourse_docker/blob/ceffc4433e1bd6fcbd101f2427e17232fc99ab14/templates/web.ratelimited.template.yml) **templates/web.ratelimited.template.yml** should be removed from the docker config and the rate limit should then be configured in the outer nginx instance instead.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [20 maart 2020 om 16:57 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/7 "2020-03-20T16:57:17Z")

</div>

No, discourse doesn’t require nginx outside the container.

Nginx already exists **inside** the container and is configured automatically. It’s zero-touch providing you followed the [standard install](https://meta.discourse.org/t/142537?silent=true).

If you aren’t running any other services on the host you don’t need an external nginx instance at all.

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [20 maart 2020 om 16:58 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/8 "2020-03-20T16:58:27Z")

</div>

Sorry, but I don’t think that 20+ minute app rebuilding without any offline page is good practice (for high traffic site).

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [20 maart 2020 om 17:00 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/9 "2020-03-20T17:00:11Z")

</div>

Manual rebuilds which require downtime happen once or twice a year. If you upgrade via /admin/upgrade the upgrades are seamless.

You can significantly reduce your rebuild times with a two-container install and I would recommend you look into this regardless of whether you use nginx.

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [20 maart 2020 om 17:07 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/10 "2020-03-20T17:07:45Z")

</div>

Two-container install sounds good. But I can’t find any documentation on that here on forum ☹ ..

---

<div class="post-metadata">

### Author: ![justin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin/32/157614_2.png) [@justin](https://meta.discourse.org/u/justin)
#### Post date: [20 maart 2020 om 17:14 UTC](https://meta.discourse.org/t/nginx-rate-limiting-outside-of-container-any-tips/143711/11 "2020-03-20T17:14:52Z")

</div>

> [@Overgrow](#):
>
> a) AFAIK nginx outside of container is recommended

No it is not. It’s _possible_ but not a standard recommendation.

Here’s the guide.

> [@Move from standalone container to separate web and data containers](https://meta.discourse.org/t/how-to-move-from-standalone-container-to-separate-web-and-data-containers/29413):
>
> warning This is an advanced setup. Don’t follow this unless you are experienced with Linux server administration and Docker. You also need to pay close attention to commits to discourse\_docker to make sure you notice if there’s a version bump for postgres or redis. Converting your Current Setup I managed to migrate to two containers. If anyone else needs instructions, this is how it worked for me. The process includes backup, setting up separate web and data containers and restore data. …

If your main concern is downtime during rebuilds, that’s going to be your best bet. If you need help setting that up, someone in #Marketplace will be able to help.
