nginx已經配置server及端口20002,telnet不通:telnet 127.0.0.1 20002 Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused
一、檢查
systemctl status nginx.service
nginx: [emerg] bind() to 0.0.0.0:20002 failed (13: Permission denied)
二、解決阻止nginx bind端口問題
yum install policycoreutils-python
semanage port -a -t http_port_t -p tcp 20002
問題 | CentOS 7 解決方案 |
---|---|
dnf ?不可用 | 使用?yum |
semanage ?不可用 | yum install policycoreutils-python |
SELinux 阻止 Nginx 綁定端口 | semanage port -a -t http_port_t -p tcp 20002 |
臨時測試 SELinux 影響 | setenforce 0 (僅測試用) |
檢查端口是否被占用 | ss -tulnp | grep 20002 |
三、重啟
systemctl restart nginx
四、本地測試
curl http://localhost:20002? ?本地訪問響應OK
五、遠端測試
客戶端通過游覽器訪問http://ip:20002 無響應
開放端口
sudo firewall-cmd --zone=public --add-port=20002/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports
客戶端通過游覽器訪問http://ip:20002 響應OK