# Reverse proxy X-Forwarded-For

**URL:** https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181
**Category:** Support
**Tags:** unsupported-install, nginx
**Created:** [May 17, 2026, 4:27am UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181 "2026-05-17T04:27:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Eviepayne](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviepayne/32/352733_2.png) [@Eviepayne](https://meta.discourse.org/u/Eviepayne)
#### Post date: [May 17, 2026, 4:27am UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/1 "2026-05-17T04:27:02Z")

</div>

I recently migrated my forum to a much more performant host, and I am working towards high availability.

in the reverse proxy I added the Forward Proto and For headers but the nginx configuration on the discourse only respected the Proto.

I had to add under server:

```nginx
set_real_ip_from loadbalancerip;
real_ip_header X-Forwarded-For;

```

Is there a discourse envvar to add these?  
or possibly a argument to add to app.yml?

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [May 17, 2026, 5:34am UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/2 "2026-05-17T05:34:02Z")

</div>

I believe this is what you’re looking for:

> [@Run other websites on the same machine as Discourse](https://meta.discourse.org/t/run-other-websites-on-the-same-machine-as-discourse/17247):
>
> @pfaffman edited this heavily 2022.02.24. Blame me if it’s broken. If you want to run other websites on the same machine as Discourse, you need to set up an extra NGINX or HAProxy proxy in front of the Docker container. NOTE: This is for advanced admins This guide assumes you already have Discourse working - if you don’t, it may be hard to tell whether or not the configuration is working. You cannot use ./discourse-setup to set up Discourse if another server is using port 80 or 443. You will…

---

<div class="post-metadata">

### Author: ![Eviepayne](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviepayne/32/352733_2.png) [@Eviepayne](https://meta.discourse.org/u/Eviepayne)
#### Post date: [May 17, 2026, 5:44am UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/3 "2026-05-17T05:44:57Z")

</div>

No this guide explains how to setup an nginx socket that’s shared between the container and host.

I’m trying to find a declarative way to include:

```plaintext
set_real_ip_from loadbalancerip;
real_ip_header X-Forwarded-For;

```

In the nginx configuration in containers after rebuild.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [May 17, 2026, 5:47am UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/4 "2026-05-17T05:47:59Z")

</div>

You’re trying to add this to the container’s internal nginx? I believe that’s unnecessary because it’s added by default:

> <https://github.com/discourse/discourse/blob/main/config/nginx.sample.conf#L105>

---

<div class="post-metadata">

### Author: ![Eviepayne](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviepayne/32/352733_2.png) [@Eviepayne](https://meta.discourse.org/u/Eviepayne)
#### Post date: [May 17, 2026, 5:56am UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/5 "2026-05-17T05:56:18Z")

</div>

> [@Eviepayne](#):
>
> `set_real_ip_from loadbalancerip;`

This line is needed for that to work.  
Without it all the requests are still the loadbalancer IP.  
I know because my discourse was down for 429 errors.

In case it’s not clear this is my infra:  
user \> haproxy \> discourse

Discourse of course includes an nginx rproxy

I included the forwarding headers in haproxy but the discourse internal nginx was not respecting forwarded for. I had to add the 2 lines in my OP and restart the container for it to work.

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [May 17, 2026, 3:28pm UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/6 "2026-05-17T15:28:55Z")

</div>

> [@Eviepayne](#):
>
> I recently migrated my forum to a much more performant host, and I am working towards high availability.

are you using a 2-containter build?

i don’t think there is built-in env variable for custom load balancer IPs, because nginx doesn’t natively read those vars for the server block.

also, if you manually edited the nginx config inside the running container, it will be wiped out the next time you rebuild.

i think in order to make it permanent and survive rebuilds, you need to use the replace command in your `app.yml` (or `web_only.yml` if dual container) - scroll to the very bottom of your `.yml` file to the `run:` section, and add this block. it tells the discourse builder to automatically inject your real ip settings after the `server {` block opens:

```plaintext
run:
  - replace:
      filename: /etc/nginx/conf.d/discourse.conf
      from: /server.+{/
      to: |
        server {
          set_real_ip_from 192.168.1.100; ## Replace with your actual load balancer ip/subnet
          real_ip_header X-Forwarded-For;
          real_ip_recursive on;

```

(make sure indentation and spacing match the rest of run block, `yml` files are super strict)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [June 16, 2026, 3:29pm UTC](https://meta.discourse.org/t/reverse-proxy-x-forwarded-for/403181/7 "2026-06-16T15:29:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
