How to install Discourse alongside Virtualmin

OS type and version Ubuntu 22.04
Webmin version 2.105
Virtualmin version 7.9.0

I saw it was asked a few times, so here’s a quick guide.

Install Discourse

From Discourse’s folder,

  • Don’t run ./discourse-setup

  • cp ./samples/standalone.yml ./containers/app.yml
  • Edit app.yml: domain, email, SMTP credentials, etc.

    • Comment out the exposed ports:
      # expose:
      # - "80:80"   # http
      # - "443:443" # https
    • Disable SSL and add the proper template to create Nginx sock. It should look like this:
      # base templates used; can cut down to include less functionality per container templates:
        - "templates/postgres.template.yml"
        - "templates/redis.template.yml"
        - "templates/web.template.yml"
        # - "templates/web.ssl.template.yml" # remove - https will be handled by outer nginx
        # - "templates/web.letsencrypt.ssl.template.yml" # remove -- https will be handled by outer nginx
        - "templates/web.ratelimited.template.yml"
        - "templates/web.socketed.template.yml"  # <-- Added
  • ./launcher rebuild app

Configure Virtualmin

  • Create Virtual Sever →

    • Only tick Enable Nginx/Apache website

:information_source: If it wasn’t done automatically, create a Let’s Encrypt certificate:

  • Manage Virtual Server → Setup SSL Certificate → Let’s Encrypt tab

If Virtualmin uses Apache

  • Webmin → Servers → Apache Webserver → Open both port 80 and 443 files

  • In the Port 80 file, add:

    RewriteCond %{SERVER_NAME}
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / unix:/var/discourse/shared/standalone/nginx.http.sock|http://localhost/
    ProxyPassReverse / unix:/var/discourse/shared/standalone/nginx.http.sock|http://localhost/

    (don’t forget to replace

  • Save

  • In the Port 443 file, add:

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / unix:/var/discourse/shared/standalone/nginx.http.sock|http://localhost/
    ProxyPassReverse / unix:/var/discourse/shared/standalone/nginx.http.sock|http://localhost/
  • Save

:information_source: If necessary, restart Apache:

systemctl restart apache2

If Virtualmin uses Nginx

  • Webmin → Servers → Nginx Webserver → Edit Configuration Files

  • Select the right vhost file in the top file selector

  • In the server { block, add:

    location / {
          proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
          proxy_set_header Host $http_host;
          proxy_http_version 1.1;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header X-Real-IP $remote_addr;
  • Save & Close → :arrows_counterclockwise: Apply Nginx Configuration

Configure Discourse

  • Enable the force https setting

Now Discourse should be installed along Virtualmin and running.

Guides used for reference: Run other websites on the same machine as Discourse - sysadmin - Discourse Meta and Discourse behind reverse proxy and https - #3 by neounix - installation - Discourse Meta

1 Like

nginx is not required. You can proxy in Apache, too.

1 Like

It would be very interesting and appropriate if you thought about allowing the quick switch between Apache and Nginx installations with the installations already available in the Panels.

Indeed :+1:

If someone wants to explain how to do this with Apache as well, that could be useful. Unfortunately, I know pretty much nothing about system administration and can’t do it myself. :see_no_evil:

Automatically trying to convert between Apache and nginx configs is complicated and risky; particularly going from Apache to nginx, since nginx is missing features found in Apache (no htaccess file support, for instance), so it’s easy for sites to break in ways we can’t automatically fix. I’d rather people just relax about web servers. It’s never the bottleneck, and both are fine. People should just use the one they’re comfortable with.

Googling “discourse proxy Apache” finds many results. This one is sane (many are not, I found one that included both HAProxy and nginx in addition to Apache…that’s three f’ing proxies!):

That thread also has stupid replies about Apache causing problems with Discourse, which is entirely fictional. It’s just proxying. Apache is a very fine proxy.

Proxying is a few lines of configuration. Virtualmin GPL now has the Proxy Paths feature, as well, which just came down from Virtualmin Pro in the most recent release. But, I don’t think the suggested “ProxyPreserveHost” option (which I guess is needed for the “block user and IP” feature of Discourse) is available in the Proxy Paths GUI. I’ll see if we can make that available in a future release.


I edited the guide and added instructions for Apache. :+1:

1 Like

My biggest problem was the cert process. If I do it in Apache, I have one browser that complained the images were coming from a different site. Just Firefox though.

The image prob is bad editing of the web page, the image src location has http:// rather then https://

I don’t remember the exact error but the images I think were just normal Discourse stuff. In this case I think I added some things for the large and small images.

Normally the error would be mix content error.
Use inspect in the browser and search for http://

Discourse forum does has a few discussion’s about it.
like this, I think this is what you mean.

When setting it up I ran into the problem of conflicting SSL. Some folks seem to have had success in getting Apache to defer to the Discourse container, some, not so much. It would seem preferable to let Discourse handle it all. But, I’m still playing with some sites when I have time. Right now, I have none.

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