NGINX Template for Discourse

Hello there,

So I have a couple of sites already added to the panel, now it seems like the discourse site setup is kinda complicated, couldn’t get through.

Tried to follow their guide: https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247

I’ve set up a template for discourse in the templates directory and applied it to the domain name. Any of you guys have successfully installed discourse to work with other sites on the Hestia panel? If so, a template and little bit of instructions on how it is done will be highly appreciated. Thank you.

discourse.stpl

server {
    listen      %ip%:%proxy_ssl_port% ssl http2;
    server_name %domain_idn% %alias_idn%;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

    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;
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      https://%ip%:%web_ssl_port%;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
}

discourse.tlp

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;

    include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;        

    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;
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:%web_port%;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/%domain%/nginx.conf_*;
}

Just checked the template where forum.hestiacp.com is running on. Should work fine for multiple websites. Don’t know about multiple discourse sites on 1 server…

Tested the templates, but it throws an error during nginx -t

2J54p90dM3

Replace %proxy_port% with %web_port% and %proxy_ssl_port% with %web_port_ssl%

You are running Hestia + PHP-fpm probally

Yeah, that worked out. But at the end of the ./launcher rebuild app command, it says that 443 port is already used.

So I guess if you want to deploy discourse instance, it must be the first site to be added to the panel, then others :confused:

I don’t use Disclosure (Stole it HestiaCP server…) my self but probally you have to host the disclosure app on different port

1 Like

for sure :slight_smile:

Well, if I change the port to a random number in the template for discord, and set the same in the app.yml config file - the site returns 404 as it could not pair with the discourse config for some reason.

We currently solve it over a socket, not a port as you can see in our templates above. Probaly a port should also work, but stick to the socket - as we write on it, i can confirm that all works as it should :slight_smile: .

So in app.yml, I have to comment out the 80 and 443 ports, use the above template, and set the backend template to socket?
XVVpc8oNwu

EDIT:
Finally got it working, had an issue in app.yml. Thanks guys!

1 Like

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