# How to install Discourse behind Apache mod\_proxy?

**URL:** https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763
**Category:** Self-hosting
**Created:** [October 11, 2019, 7:38am UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763 "2019-10-11T07:38:52Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![hexadecagram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hexadecagram/32/262658_2.png) [@hexadecagram](https://meta.discourse.org/u/hexadecagram)
#### Post date: [October 11, 2019, 7:38am UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/1 "2019-10-11T07:38:52Z")

</div>

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!

---

<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: [October 11, 2019, 8:59am UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/2 "2019-10-11T08:59:43Z")

</div>

Have a look at [Set up Discourse on a server with existing Apache sites](https://meta.discourse.org/t/how-to-set-up-discourse-on-a-server-with-existing-apache-sites/30013)

---

<div class="post-metadata">

### Author: ![hexadecagram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hexadecagram/32/262658_2.png) [@hexadecagram](https://meta.discourse.org/u/hexadecagram)
#### Post date: [October 11, 2019, 8:39pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/3 "2019-10-11T20:39:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [October 11, 2019, 8:42pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/4 "2019-10-11T20:42:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hexadecagram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hexadecagram/32/262658_2.png) [@hexadecagram](https://meta.discourse.org/u/hexadecagram)
#### Post date: [October 11, 2019, 9:05pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/5 "2019-10-11T21:05:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hexadecagram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hexadecagram/32/262658_2.png) [@hexadecagram](https://meta.discourse.org/u/hexadecagram)
#### Post date: [October 11, 2019, 10:41pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/6 "2019-10-11T22:41:58Z")

</div>

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.

---

<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: [October 11, 2019, 11:08pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/7 "2019-10-11T23:08:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hexadecagram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hexadecagram/32/262658_2.png) [@hexadecagram](https://meta.discourse.org/u/hexadecagram)
#### Post date: [October 16, 2019, 10:56pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/8 "2019-10-16T22:56:37Z")

</div>

HAProxy does what I’m after and looks like a very polished and useful tool. Thanks for the pointer.

However, it seems that editing templates/web\*.yml to listen on ports other than the defaults of 80 and 443 was where the trouble was. I restored the default configs then edited containser/app.yml to have lines similar to the following, and the 404 errors went away:

```
expose:
  - "127.0.0.1:1234:80" # http

```

---

<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: [October 16, 2019, 11:15pm UTC](https://meta.discourse.org/t/how-to-install-discourse-behind-apache-mod-proxy/130763/9 "2019-10-16T23:15:25Z")

</div>

I’ve been really happy with traefik lately, and it’ll do let’s encrypt certificates automatically (you can do that with HA-Proxy too, it’s just a bit more work.)

Glad you figured it out!
