Running 2 hosts behind haproxy fails with random 404s

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.

1 Like

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)

4 Likes

@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?

1 Like

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?

3 Likes

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
3 Likes