配置方式
在 /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 都跑起來了。