Nginx 出现 502 网关错误?

已解决:禁用 Nginx 服务器,运行 discourse-setup,启用 Nginx 服务器并重建应用。

您好。我正在尝试按照此指南安装 Discourse。

这是我编辑后的 app.yml(从 Discourse 文件夹复制并根据指南编辑):

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/web.socketed.template.yml"
## 如果您想添加 Lets Encrypt (https),请取消注释这两行
#  - "templates/web.ssl.template.yml"
#  - "templates/web.letsencrypt.ssl.template.yml"

## 此容器应暴露哪些 TCP/IP 端口?
## 如果您希望 Discourse 与 Apache 或 Nginx 等其他 Web 服务器共享端口,
## 请参阅 https://meta.discourse.org/t/17247 了解详情
expose:
#  - "80:80"   # http
#  - "2222:22"
#  - "443:443" # https

这是我的 discourse.conf Nginx 配置块:
server {

server_name forum.myhost;  #
listen [::]:443 ssl http2 ipv6only=on; # 由 Certbot 管理
listen 443 ssl http2; # 由 Certbot 管理
ssl_certificate /etc/letsencrypt/live/forum.myhost/fullchain.pem; # 由 Certbot 管理
ssl_certificate_key /etc/letsencrypt/live/forum.myhost/privkey.pem; # 由 Certbot 管理
include /etc/letsencrypt/options-ssl-nginx.conf; # 由 Certbot 管理
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # 由 Certbot 管理
ssl on;
http2_idle_timeout 5m; # 从默认的 3m 上调

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;
} # 由 Certbot 管理

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

    listen 80;
    listen [::]:80;

    server_name forum.myhost;
return 404; # 由 Certbot 管理
}

服务器已启用 SSL(已安装 Certbot),并将主域名的 HTTP 重定向到 HTTPS,但论坛域名显示 502 网关错误。我正在使用 Cloudflare(未启用性能或安全选项)。

非常感谢您的任何帮助。我无法执行 discourse-setup,因为它显示“Google: 'open ports YOUR CLOUD SERVICE’以获取解决此问题的信息”。

已检查防火墙。

编辑:可能是这一行的问题?(我在文件夹中没看到这个文件)
proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;

1 个赞

为什么使用 nginx 作为代理?

这台服务器上还有其他网站吗?

2 个赞

是的,Stephen,我正在使用 nginx,并计划上传一个 Drupal 站点。正如我所评论的,默认域名已启用 SSL,但论坛子域名显示 502 网关错误。

好的,我在服务器上停止了 nginx,discourse-setup 可以运行,但我现在看到了以下错误信息:

正在启用 Let’s Encrypt
web.ssl.template.yml 未启用——它之前是启用的吗?
letsencrypt.ssl.template.yml 未启用——它之前是启用的吗?

不幸的是,更改过程中出现错误

-d 这可能是由于您进行了意外的更改。

我真的不确定,如果我的服务器上已经安装了 Let’s Encrypt,我是否需要使用 Discourse 自带的 Let’s Encrypt,还是使用外部的。

感谢您的阅读。

最后编辑: 我刚刚启动了服务器 nginx,主域名和次级域名现在都能正常工作(在 Discourse 实例中保留了通过 Certbot 配置的服务器 Let’s Encrypt)。

2 个赞

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