502 Gateway Error on Nginx?

SOLVED: disabling server nginx, running discourse-setup, enabling server nginx and rebuilding the app.

Hi there. I trying to install Discourse following this guide.

This is my edited app.yml (copied from discourse folders and edited following the guides):

  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/web.socketed.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
#  - "templates/web.ssl.template.yml"
#  - "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
#  - "80:80"   # http
#  - "2222:22"
#  - "443:443" # https

That’s my discourse.conf nginx block:
server {

server_name forum.myhost;  #
listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/forum.myhost/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/forum.myhost/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
ssl on;
http2_idle_timeout 5m; # up from 3m default;

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 https;
    proxy_set_header X-Real-IP $remote_addr;
server {
if ($host = forum.myhost) {
    return 301 https://$host$request_uri;
} # managed by Certbot

server_name www.forum.myhost;
return 301 $scheme://forum.myhost$request_uri;

    listen 80;
    listen [::]:80;

    server_name forum.myhost;
return 404; # managed by Certbot

The server is working with SSL (Certbot installed) and redirects http to https in primary domain but forum domain shows 502 Gateway error. I’m using Cloudflare (without performance or security options enabled).

Any kind of help will be very appreciated. I can’t execute discourse-setup because it shows “Google: “open ports YOUR CLOUD SERVICE” for information for resolving this problem.”

Checked firewall too.

EDIT: Maybe a problem with this line? (I don’t see this file in folder)
proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;

1 Like

Why are you using nginx as a proxy?

Are there other websites on this server?


Yep Stephen, I’m using nginx and have plans to upload a Drupal site. Default domain is working with SSL as I commented, and forum subdomain shows 502 gateway error.

OK, I stopped nginx in my server and discourse-setup works but I now see this error message:

Enabling Let’s Encrypt
web.ssl.template.yml NOT ENABLED–was it on already?
letsencrypt.ssl.template.yml NOT ENABLED – was it on already?

Unfortunately, there was an error changing

-d This may happen if you have made unexpected changes.

I really don’t know if I need to use let’s encrypt from Discourse or outside if I have it installed in my server.

Thanks for reading.

LAST EDIT: I just start server nginx and primary and secondary domains are working (keeping server let’s encrypt from Certbot in Discourse instance)


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