大家好,
我的网站出现了 502 Bad Gateway 错误,无法解决 nginx.http.sock 相关的问题。
Nginx 错误日志:
[crit] 14339#14339: *1 connect() to unix:/var/discourse/shared/standalone/nginx.http.sock failed (2: No such file or directory) while connecting to upstream, client: **.***.***.***, server: mydomain.net, request: "GET / HTTP/2.0", upstream: "http://unix:/var/discourse/shared/standalone/nginx.http.sock:/", host: "mydomain.net", referrer: "https:/mydomain.net/" "
以下是我的 discourse.conf 配置:
server {
listen 80;
listen [::]:80;
server_name mydmain.net www.mydomain.net; # <-- 请修改此处
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mydomain www.mydomain.net; # <-- 请修改此处
ssl on;
ssl_certificate /etc/letsencrypt/live/mydomain.net/fullchain.pem; # 由 Certbot 管理
ssl_certificate_key /etc/letsencrypt/live/mydomain.net/privkey.pem; # 由 Certbot 管理
ssl_dhparam /etc/letsencrypt/live/mydomain.net/dhparams.pem;
include /etc/nginx/snippets/ssl.conf;
http2_idle_timeout 5m; # 从默认的 3m 提升为 5m
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;
}
}
我的 app.yml 配置:
templates:
- "templates/postgres.template.yml"
- "templates/redis.template.yml"
- "templates/web.template.yml"
- "templates/sshd.template.yml"
- "templates/web.ratelimited.template.yml"
## 如果希望添加 Lets Encrypt (https),请取消下面两行的注释
- "templates/web.ssl.template.yml"
- "templates/web.letsencrypt.ssl.template.yml"
## - "templates/web.socketed.template.yml"
## 此容器应暴露哪些 TCP/IP 端口?
## 如果您希望 Discourse 与 Apache 或 Nginx 等其他 Web 服务器共享端口,
## 请参阅 https://meta.discourse.org/t/17247 了解详情
#expose:
# - "2045:80" # http
# - "1443:443" # https
我也尝试取消注释 “templates/web.socketed.template.yml”,但 Nginx 错误日志中的结果仍然相同。我该如何解决这个问题?我已经想不出其他办法了。请帮忙;/
我不是专家,除非我错了,如果你选择 socket 方式,你可能需要取消注释 web.socketed.template。
我刚在我的安装环境中尝试了一下(之前使用的是监听端口的方式),它现在可以正常工作了。
你需要确保:
- 注释掉 SSL/Let’s Encrypt 相关的模板,因为它们已经由你外部的 Nginx 配置处理了。
- 重新构建应用,这样
nginx.http.sock 文件就会出现在 /var/discourse/shared/standalone/ 目录中。
请确保
- SSL/Let’s Encrypt 模板已被注释,因为您的外部 Nginx 配置已处理。
- 重新构建应用,以便
nginx.http.sock 文件出现在 /var/discourse/shared/standalone/ 目录中。
好的,但这一行会发生什么情况呢?502 网关错误消失了,网站也已上线,但由于这一行,我仍然看到相同的 Nginx 错误。
location / {
proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock;
SSL 似乎无法正常工作,图片也无法显示。我在设置论坛时上传了一个标志。
如果尚未操作,请尝试启用 force https Discourse 选项(安全标签页)
OMGGG!!! 太感谢你了 <3 。我欠你一些水果
。现在我得想办法让 SMTP 工作,因为用 Yandex 时它不起作用,注册测试用户时我收不到任何邮件。
Mednosis
(Mednosis)
8
我尝试了上述所有建议,但依然收到 502 错误网关。目前我没有使用 HTTPS。
以下是我的错误信息:
> 2020/04/02 00:17:54 [crit] 18599#18599: *1 connect() to unix:/var/discourse/shared/standalone/nginx.http.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xxx.xx, server: talk.mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/discourse/shared/standalone/nginx.http.sock:/", host: "talk.mydomain.com"
>
> 2020/04/02 00:17:54 [crit] 18599#18599: *1 connect() to unix:/var/discourse/shared/standalone/nginx.http.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xxx.xx, server: talk.mydomain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/var/discourse/shared/standalone/nginx.http.sock:/favicon.ico", host: "talk.mydomain.com", referrer: "http://talk.mydomain.com/"
以下是我的 /etc/nginx/sites-enabled/discourse.conf 文件内容:
server {
listen 80; listen [::]:80;
server_name talk.mydomain.com;
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;
}
}
以下是 /var/discourse/containers/app.yml 中的模板部分:
server {
listen 80; listen [::]:80;
server_name talk.mydomain.com;
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;
}
}
请给予指导。