【发布时间】:2019-06-27 00:37:29
【问题描述】:
我正在尝试运行一个简单的 Python http 服务器,它使用微型实例在端口 8080 上显示“hello world”。我还有 4 个 Tornado 实例在 Nginx 后面运行。在 80 端口上连接 Nginx/Tornado 没有问题。
我已将端口 8080 添加到我的防火墙设置中,并确保端口 8080 已打开并在服务器上侦听,但无论我做什么,我的连接总是被拒绝。我尝试使用浏览器、telnet 和 wget 进行连接,但每个连接都被拒绝。
这是netstat -an | grep "LISTEN "的输出
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8002 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8003 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::8000 :::* LISTEN
tcp6 0 0 :::8001 :::* LISTEN
tcp6 0 0 :::8002 :::* LISTEN
tcp6 0 0 :::8003 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
这是我的 iptables 列表
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
这是我正在使用的 Python 脚本:
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
PORT_NUMBER = 8080
#This class will handles any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Send the html message
self.wfile.write("Hello World!")
return
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()
【问题讨论】:
-
这里有一些好的方向,由于现场的自动完成,我错过了一件事,就是在源 IP 末尾的
/0用于入口。一旦我将它添加到`0.0.0.0`,它就起作用了。