认证高级PHP讲师
「2017.1.6更新開始"
請問你是想透過nginx反向代理node的服務嗎?
如果是,請將root資訊刪除:
root /usr/web;
「2017.1.6更新結束"
首先,你nginx的配置是沒問題的,但可以修改成以下格式:
server { listen 8089; root /usr/web; location / { index index.html; proxy_pass http://127.0.0.1:3000; } }
接著請透過以下指令確認你的nginx正處於運作狀態:
[root@centos-test ~]# ps -aux | grep nginx root 1376 0.0 0.5 122948 5128 ? Ss 19:02 0:00 nginx: master process nginx nginx 1406 0.0 0.3 123180 3616 ? S 19:03 0:00 nginx: worker process nginx 1407 0.0 0.4 123180 4100 ? S 19:03 0:00 nginx: worker process root 1410 0.0 0.0 112664 932 pts/0 R+ 19:03 0:00 grep --color=auto nginx
還可以透過以下命令確認你的nginx正監聽著正確的連接埠:
[root@centos-test ~]# netstat -anp | grep 8089 tcp 0 0 0.0.0.0:8089 0.0.0.0:* LISTEN 1376/nginx: master tcp 0 0 10.1.1.118:8089 10.1.1.66:54931 ESTABLISHED 1407/nginx: worker tcp 0 0 10.1.1.118:8089 10.1.1.66:54932 ESTABLISHED 1407/nginx: worker
如果nginx確認是運作正常,那麼請透過以下指令確認iptables是處於放行狀態:
[root@centos-test ~]# iptables -L -vn
要注意的是,iptables在預設狀態下的FORWARD鏈中含有一條REJECT規則:
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
你可以透過以下命令將其刪除:
#先显示规则行数 [root@centos-test ~]# iptables -L -vn --line-number Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited #然后删除该规则 [root@centos-test ~]# iptables -D FORWARD 1 #保存并重新加载 [root@centos-test ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] [root@centos-test ~]# service iptables reload Redirecting to /bin/systemctl reload iptables.service
在這裡要注意的是,你的iptables中INPUT鏈的預設規則是ACCEPT,並不需要手動新增放行規則。
如果nginx還不能訪問,請檢查proxy_pass的伺服器是否運作正常。
nginx是不是沒重啟啊
直接公網ip:3000 可以存取嗎?nginx 不能存取的日誌資訊呢 ? apache 的日誌資訊呢 ?
service iptables stop
關閉防火牆 或 新增對應連接埠規則
「2017.1.6更新開始"
請問你是想透過nginx反向代理node的服務嗎?
如果是,請將root資訊刪除:
「2017.1.6更新結束"
首先,你nginx的配置是沒問題的,但可以修改成以下格式:
接著請透過以下指令確認你的nginx正處於運作狀態:
還可以透過以下命令確認你的nginx正監聽著正確的連接埠:
如果nginx確認是運作正常,那麼請透過以下指令確認iptables是處於放行狀態:
要注意的是,iptables在預設狀態下的FORWARD鏈中含有一條REJECT規則:
你可以透過以下命令將其刪除:
在這裡要注意的是,你的iptables中INPUT鏈的預設規則是ACCEPT,並不需要手動新增放行規則。
如果nginx還不能訪問,請檢查proxy_pass的伺服器是否運作正常。
nginx是不是沒重啟啊
直接公網ip:3000 可以存取嗎?
nginx 不能存取的日誌資訊呢 ?
apache 的日誌資訊呢 ?
關閉防火牆 或 新增對應連接埠規則