Ghost CLI 502 Bad Gateway

  |   ghost Nginx Linux

我正在尝试在服务器上建立一个Ghost博客。我已经启动并运行了博客,但我只能通过其IP地址访问它。当我输入域名时,我收到了502 Bad Gateway / nginx错误。但正如我所说,nginx配置没有错误的,而且输入IP地址工作正常。

当我查看Nginx站点错误日志

2019/01/02 01:35:47 [crit] 29810#29810: *34 connect() to 127.0.0.1:2369 failed (13: Permission denied) while connecting to upstream, client: 192.168.0.12, server: www.zhouyulong.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:2369/", host: "145.193.10.120"

以上报错信息13: Permission denied就说明nginx的权限问题,应该证明我的问题是由于SELinux。

应该解决如下:

setsebool -P httpd_can_network_connect 1

我检查了SELinux日志中的错误:

sudo cat /var/log/audit/audit.log | grep nginx | grep denied

并发现运行以下命令修复了我的问题:

sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
sudo semodule -i mynginx.pp

(13: Permission denied) while connecting to upstream:[nginx]