Redirect to discourse from a route in another domain

Hi!

I need to put the discourse forum under a URL like https://mydomain.com/forum.

I have installed NGinx in the server which hosts discourse (forum.mydomain.com) , and redirected it to the discourse instance, something similar to this: https://serversforhackers.com/video/installing-discourse-with-docker but without divide it in 3 containers.

In mydomain.com server I have the next configuration:

location /forum {
    rewrite  ^/forum/(.*)  /$1 break;
    proxy_pass https://forum.mydomain.com;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

And the configuration of forum.mydomain.com is:

upstream discourse {
    server 127.0.0.1:8080;
}

server {
    listen 80 default_server;
    server_name mydomain.com/forum;
    return 301 https://mydomain.com/forum$request_uri;
}

server {
    listen 443 default_server ssl;

    client_body_buffer_size     32k;
    client_header_buffer_size   8k;
    large_client_header_buffers 8 64k;

    root /var/www/discourse/public;
    index index.html index.htm;

    access_log /var/log/nginx/discourse.log;
    error_log  /var/log/nginx/discourse.log error;

    server_name mydomain.com/forum;
    merge_slashes on;

    charset utf-8;

    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

    location ~ /.well-known {
       allow all;
    }

    location / {
        include proxy_params;
        proxy_pass http://discourse;

        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

When I access to https://mydomain.com/forum it redirects me to the forum, but fails loading CSS and shows the next error: Oops! That page doesn’t exist or is private.

There’s anyone in the room who has did this and succeed?

I’m open to any tutorial or simplest way to do this.

Thanks!

The simplest thing to do is run discourse on its own domain like forum.example.com.

If you don’t want simple, try this

2 Likes

Thanks for the link @pfaffman!

I know there’s more simple to configure it on a subdomain, but is a requirement from my client.

Finally I use this posts to set up this, and finally it’s working!

Thanks for all!

3 Likes