# Running 2 hosts behind haproxy fails with random 404s

**URL:** https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663
**Category:** Self-hosting
**Created:** [May 6, 2020, 11:16pm UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663 "2020-05-06T23:16:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![foozmeat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/foozmeat/32/107214_2.png) [@foozmeat](https://meta.discourse.org/u/foozmeat)
#### Post date: [May 6, 2020, 11:16pm UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663/1 "2020-05-06T23:16:08Z")

</div>

Today I tried adding a second server to host one of our discourse instances. The container is configured to use an external redis, postgres, and storage servers - its web-app only. Thus far we’ve been running the single server sites behind HAProxy without issues. When running with 2 servers behind HAProxy we see quite a few 404s from nginx for JS files. Removing either server from HAproxy stops the problem. The URLs for the files that 404 appear to be identical so I’m stumped as to why they wouldn’t be served by either server.

There are no overrides in the Developer settings. We’re running 2.4.3 stable.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [May 6, 2020, 11:42pm UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663/3 "2020-05-06T23:42:45Z")

</div>

If you are running more than one web container you need something to ensure both have access to the static files.

The easiest path is [Using Object Storage for Uploads (S3 Clones)](https://meta.discourse.org/t/using-object-storage-for-uploads-s3-clones/148916)

---

<div class="post-metadata">

### Author: ![foozmeat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/foozmeat/32/107214_2.png) [@foozmeat](https://meta.discourse.org/u/foozmeat)
#### Post date: [May 7, 2020, 3:32am UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663/4 "2020-05-07T03:32:20Z")

</div>

@Falco Hi thanks for the reply. The two servers use shared storage over NFS. In my container config I have this

```
volumes:
  - volume:
      host: {{ discourse_nas_path }}/data
      guest: /shared
  - volume:
      host: {{ discourse_nas_path }}/logs
      guest: /var/log

```

Each container stores its own copies of the assets generated by the `assets:precompile` step however. Is it required to shared the precompiled assets?

---

<div class="post-metadata">

### Author: ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)
#### Post date: [May 7, 2020, 5:31am UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663/6 "2020-05-07T05:31:51Z")

</div>

> [@foozmeat](#):
>
> When running with 2 servers behind HAProxy we see quite a few 404s from nginx for JS files.

Besides adding and removing backends in Haproxy what have you done to test it?

Does your Haproxy config do random backends or affinity? Is the 404 logged by Haproxy? Is the 404 logged by nginx? Is it the first or second backend that errors? Does your site require login? Can you reproduce the errors when connecting to nginx directly from behind the proxy server? Do the files being requested exist on disk? Is it all JS or just specific ones?

---

<div class="post-metadata">

### Author: ![foozmeat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/foozmeat/32/107214_2.png) [@foozmeat](https://meta.discourse.org/u/foozmeat)
#### Post date: [May 7, 2020, 5:59pm UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663/7 "2020-05-07T17:59:40Z")

</div>

Thanks to the hint from @Falco I tried adding the following to my container config and now things are working as expected:

```
  - volume:
      host: {{ discourse_nas_path }}/assets
      guest: /var/www/discourse/public/assets

```

---

<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: [January 25, 2021, 5:16pm UTC](https://meta.discourse.org/t/running-2-hosts-behind-haproxy-fails-with-random-404s/150663/8 "2021-01-25T17:16:15Z")

</div>

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