nginx 部署两个虚拟站点报错:connect() to 127.0.0.1:4000 failed (13: Permission denied)

配置方式

在 /etc/nginx/conf.d 下面,复制了里面原来的 myweb.conf ,新文件叫 wechat.conf, 修改了里面的 server_name 为第二个域名 chat.xxx.com, proxy_pass http://127.0.0.1:4000/ (因为第二个 node server 监听 4000 端口)。

报错

通过 chat.xxx.com 不能访问,显示 bad gateway,通过chat.xxx.com:4000 直接可以打开 node,感觉还是 nginx 的配置问题,但是这两个站点配置完全一样,仅仅是域名和端口不同。查看 nginx 的 errorlog,显示如下:

2016/11/23 21:31:09 [crit] 15385#0: *701 connect() to 127.0.0.1:4000 failed (13: Permission denied) while connecting to upstream, client: 112.238.203.***, server: chat.xxx.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "chat.xxx.com"

google 发现一个类似的感觉靠谱,拷贝如下,原文:
Diagnosis
Environment
Any Linux distribution that ships with SELinux

Diagnostic Steps
Check for errors in the SELinux logs: sudo cat /var/log/audit/audit.log | grep nginx | grep denied
Cause
SELinux prevent connections on port 7990 for the nginx process.
Resolution
Execute the following command in your server:

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

结果

今天没来得及测试,我的临时办法是把 chat 的 node server 端口改到 30001,两个 server 都跑起来了。

你可能感兴趣的:(nginx 部署两个虚拟站点报错:connect() to 127.0.0.1:4000 failed (13: Permission denied))