How to run Discourse as an Apache VirtualHost

Hi @Nap,

Good to read you solved your problem.

I’m running Discourse on a number of servers with Apache2 as the front end reverse proxy to a unix socket and the configuration works just fine (as we all know, it is a little bit slower than nginx, which I also run on some servers, but it works fine.)

Basically, I configure the virtual host like this:

Port 80 configuration

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName  discourse.mygreatwebsite.com
    DocumentRoot /website/discourse  # often not necessary

    RewriteEngine On
    ProxyPreserveHost On
    ProxyRequests Off
    ErrorLog /var/log/apache2/discourse.error.log
    LogLevel warn
    CustomLog /var/log/apache2/discourse.access.log combined

    RewriteCond %{SERVER_NAME} =discourse.mygreatwebsite.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Port 443 configuration:

<VirtualHost *:443>
  ServerAdmin webmaster@localhost
  ServerName  discourse.mygreatwebsite.com
  DocumentRoot /website/nginx  # mostly not required  in this configuration
  
  SSLProxyEngine on
  RewriteEngine On
  ProxyPreserveHost On
  ProxyRequests Off
  RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
  RequestHeader set X-Real-IP expr=%{REMOTE_ADDR}
  
  ProxyPass / unix:/var/discourse/shared/socket-only/discourse.http.sock|http://my.ip.address.here/
  ProxyPassReverse  / unix:/var/discourse/shared/socket-only/discourse.http.sock|http://my.ip.address.here/
  ErrorLog /var/log/apache2/discourse-ssl.error.log
  LogLevel warn
  CustomLog /var/log/apache2/discourse-ssl.access.log combined

  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/discourse.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/discourse.com/privkey.pem
</VirtualHost>

Notes:

  1. Normally, I let the letsecrypt certbot do all the work regarding setting up all the SSL certs and redirects, etc.

  2. We use the IP address which apache2 is bound (to) in the apache2 config files.

  3. We always configure this (expose) with unix sockets in the discourse container, and do not expose any TCP/IP container ports in this configuration.

Cheers and hopes this adds some value, late in the game.