Question

Hi I have Discourse installed via Docker and Apache server on the same Ubuntu 12.04 server.

Discourse container is exposed to port 81 and Apache is on port 80.

How can I setup Apache to show Apache web like "something.com" and discourse docker on something like "forum.something.com".

I used this for Discourse: https://github.com/discourse/discourse_docker

Was it helpful?

Solution 2

You can use any reverse proxy to do this.

You have one container for apache, one container for discourse (or one with both) and you do not expose any ports (do not use -p). However, you might want to use the PORT instruction if you are building the image via a dockerfile.

Once the containers are running, you should be able to access them via <ip container apache>:80 and <ip container discourse>:81 from the host.

Now you can start a new container with a reverse proxy. If you used PORT, you can even link the containers (i.e. docker run -link <apache container name>:apache -link <discourse container name>:discourse) in order to have the ips on the env.

You can use reverse proxies like apache, nginx or hipache.

When you run the reverse proxy container, you need to specify the -p 0.0.0.0:80:80 in order to have it available form outside the host.

Example of nginx config for reverse proxy using docker links: https://github.com/creack/prod/blob/master/nginx/nginx.conf#L27

OTHER TIPS

I use a separate virtual host for that. I assume you want to use SSL.

<VirtualHost *:443>
        ServerName forum.something.com
        ProxyPreserveHost On
        ProxyPass        "/" "http://localhost:2080/"
        ProxyPassReverse "/" "http://localhost:2080/"
        RequestHeader set X-Forwarded-Proto "https"
        DocumentRoot /home/pub

        [... SSL stuff ...]

</VirtualHost>

The non-SSL virtual hosts redirects to the SSL vhost:

<VirtualHost *:80>
    ServerName forum.something.com

    # Use the next lines if you want to exclude the 
    # Let's Encrypt verification URL from proxied to Discourse
    # otherwise, only use the Redirect clause.
    <LocationMatch "^/(?!\.well-known)">
                   Redirect permanent / https://forum.something.com/
    </LocationMatch>
    DocumentRoot /home/pub

The container.yml file for the Discource docker image contains

expose:
  - "127.0.0.1:2080:80"   # http

In the Discourse settings you should also enable force_https. So Discourse itself exposes no hosts to the outside world.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top