Running Discourse docker alongside Apache

Hello.

I am trying to set up Discourse docker on my existing server. I am not running any other docker containers.

My server runs Apache (WordPress websites) and some other web services.

I can’t figure out how to route my subdomain ‘forum.rebelscience.club’ to my docker container.

When I am asked this:

Hostname for your Discourse? [discourse.example.com]: forum.rebelscience.club

This is what I see:

Checking your domain name . . .
WARNING: Port 443 of computer does not appear to be accessible using hostname:  forum.rebelscience.club.
WARNING: Connection to http://forum.rebelscience.club (port 80) also fails.

This suggests that forum.rebelscience.club resolves to some IP address that does not reach this 
machine where you are installing discourse.

The first thing to do is confirm that forum.rebelscience.club resolves to the IP address of this server.
You usually do this at the same place you purchased the domain.

If you are sure that the IP address resolves correctly, it could be a firewall issue.
A web search for "open ports YOUR CLOUD SERVICE" might help.

This tool is designed only for the most standard installations. If you cannot resolve
the issue above, you will need to edit containers/app.yml yourself and then type

./launcher rebuild app

I am not sure how to set this up. Ports 80/443 are available, but they are pointed to my main domain, not my subdomain.

Any tips are highly appreciated.

Hey @rebelCoder

This topic has been discussed extensively here at meta; and you can search meta for apache reverse proxy and find a number of comprehensive and very detailed topics.

In a nutshell, you need to set up your apache server virtual host to operate as a reverse proxy to Discourse.

The exact apache2 configurations for this setup have been posted on meta a number of times.

Hope this helps.

3 Likes

Sorry, I should have mentioned I have looked at/tried a few solutions from this forum and Digital Ocean too. But I still can’t get it to work. I have never set up docker before.

Let me share my current settings:

/ets/hosts:
127.0.0.1       forum.rebelscience.club

Hosts file, DNS record work as I had phpBB running there today. Now I am trying to point it to a docker with Discourse.

In containers/app.yml

I have updated ports:

expose:
  - "8081:80"   # http
  - "8443:443" # https

In /etc/apache2/sites-enabled/discourse.conf

<VirtualHost *:80>
  ServerName forum.rebelscience.club
  ServerAlias www.forum.rebelscience.club

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
  </IfModule>
</VirtualHost>

What else am I missing? Running ./discourse-setup still fails with the message in the original post.

I believe you should have a virtualhost for 443 port, that said the port 80 error is weird, maybe you are missing something (a cname?) in your dns ?

It is strange. A bit too tedious to set up it seems.

I only have A Record for forum.rebelscience.club

I have updated my .conf files with a cert too:

cat /etc/apache2/sites-enabled/discourse.conf

<VirtualHost *:80>
  ServerName forum.rebelscience.club
  ServerAlias www.forum.rebelscience.club

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
  </IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.forum.rebelscience.club [OR]
RewriteCond %{SERVER_NAME} =forum.rebelscience.club
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

cat /etc/apache2/sites-enabled/discourse-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName forum.rebelscience.club
  ServerAlias www.forum.rebelscience.club

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
  </IfModule>

SSLCertificateFile /etc/letsencrypt/live/forum.rebelscience.club/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/forum.rebelscience.club/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Now I see 503 Service Unavailable

I am totally lost, what else I need to do. setup.sh still fails with the original message.

In the case (example configuration) above, you should only expose port 8081 on Docker (and not port 80 or port 443).

Ports 80 and 443 are exposed by the reverse proxy outside the container and that traffic is proxied to port 8081 (in your example above), the port you have exposed inside (mapped to 80 inside).

This will work only if you have mapped port 80 inside the container to port 8081 (exposed to the host).

expose:
  - "8081:80"   # http

Hope this helps.

PS: @rebelCoder, your apache2 configuration on the SSL side is missing a lot of configuration info you need.

See this post:

1 Like

This is no longer an issue and can be closed.

You cannot use discourse-setup. You will have to edit the app.yml by hand as described in the topics about running with apache.