Nginx只对80端口进行外部响应

我正在尝试设置一个用于Django的Nginx服务器。 首先,我只是想让它在一个非标准的端口上运行。

它什么时候工作?

我使用默认configuration安装了nginx,并马上看到基本的欢迎页面,如果我在浏览器中访问我的服务器IP地址。

如果我将sites-available / default中的端口更改为80以外的任何其他端口,我会得到很长的响应时间,然后超时。 这个人似乎有一个类似的问题,但没有答复是张贴。

在这里输入图像说明

我的设置

我在跑:

  • nginx 1.10.1
  • Ubuntu 14.04.5
  • 我没有运行防火墙
  • 我有Wooey安装,虽然服务器没有运行(这是一个Django的开发服务器)
  • 所有我已经在nginx安装更改是listen: 80 listen: 81 。 它在端口80上完美运行,在端口81上没有任何运行。
  • 我试图将服务器名称更改为机器的IP,但是没有帮助。
  • 这是一个数字海洋VPS,所以唯一的东西就是我安装的东西。
  • wget localhost:81下载服务器页面,显然它在内部工作,但是没有任何对外发生

我错过了什么? 我不知道如何进一步debugging。

IP表输出

 Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT all -- loopback/8 anywhere reject-with icmp-port-unreachable ACCEPT icmp -- anywhere anywhere state NEW icmp echo-request ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables_INPUT_denied: " REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain FORWARD (policy ACCEPT) target prot opt source destination LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables_FORWARD_denied: " REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) target prot opt source destination 

netstat -napl相关输出

 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 903/sshd tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 756/nginx -g daemon 

Nginx错误日志只显示此消息(access.log为空)

2016/12/17 21:17:08 [notice] 14556#14556: signal process started

Nginx的configuration是默认的:

默认服务器configuration

 server { listen 81 default_server; #listen [::]:80 default_server; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name my_ip; ... 

在您的防火墙规则中,我们可以阅读:

 ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW 

我找不到允许在81号港口的交通规则。

你知道在这个服务器上的iptablespipe理的地方吗? 你可能会想在那里复制一个规则。

您应该能够直接使用iptables进行非永久更改:

 iptables -I INPUT -p tcp -m state --state NEW --dport 81 -j ACCEPT 

简短的版本

 sudo ufw allow 81