How to install Discourse behind Apache mod_proxy?

Hi all.

I am trying to set up Discourse in a Docker container. The host environment (Debian) is running an Apache httpd server (I can’t run nginx because I’m hosting other sites on Apache). I want to use mod_proxy to reverse-proxy to the container, which is listening on port 3000.

Apache’s current config for this vhost is as follows:

<VirtualHost *:80>
  ServerAdmin webmaster@example.com
  ServerName example.com
  ServerAlias www.example.com

  ErrorLog ${APACHE_LOG_DIR}/vhosts/example.com/error.log
  CustomLog ${APACHE_LOG_DIR}/vhosts/example.com/access.log combined

  <IfModule proxy_module>
  ## <https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247>
    ProxyPreserveHost on
    RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
    RequestHeader set X-Real-IP expr=%{REMOTE_ADDR}
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
  </IfModule>
</VirtualHost>

I started with just the ProxyPass and ProxyPassReverse directives and added ProxyPreserveHost and the RequestHeader directives one at time. No matter how I configure the proxy using these directives, certain files below the document root return 404 when accessed (for example stuff in /images and /assets).

Note the comment containing the Discourse Meta URL that I converted from nginx syntax to Apache.

Any thoughts on how to get this to work would be much appreciated!

Have a look at How to set up Discourse on a server with existing Apache sites

2 Likes

So the solution you’re proposing is to run Discourse behind HAProxy behind Apache?

As I said, I have to use Apache at the front because I am hosting other vhosts on this machine.

Why not nginx? I’m not sure of the performance on discourse with apache.

I don’t have the time or resources to switch to nginx at the moment.

To be clear, Discourse itself would be running on nginx but it needs to be proxied through Apache.

1 Like

I’ve done a bit more looking into this and I think I can accomplish what I’m after because it seems HAProxy can choose backends based on vhost.

Sorry. I did the wrong search. Perhaps you can try again and find a #howto for Apache.

1 Like