rya*_*vas 26 google-compute-engine
我正在尝试运行一个简单的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
Run Code Online (Sandbox Code Playgroud)
这是我的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
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的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()
Run Code Online (Sandbox Code Playgroud)
Adr*_*ián 33
您的网络是否具有相应的防火墙规则?按照以下步骤创建它.
转到开发人员控制台,然后单击相应的项目.
点击'计算'
点击"网络"
单击相应网络的名称.您可以在"计算引擎"部分下单击"VM实例"或使用以下命令查看您的实例所在的网络:
gcloud compute instances describe <instance> | grep "network:" | awk -F/ '{print $(NF)}'
在"防火墙规则"部分下,单击"新建"
输入防火墙规则的名称,并在"协议和端口"字段中输入:tcp:8080
保存规则
之后,您应该能够访问您的HTTP服务器.
否则,您可以尝试使用以下命令查看您的计算机是否在该端口中收到SYN TCP数据包: sudo tcpdump -i eth0 port 8080
希望能帮助到你
| 归档时间: |
|
| 查看次数: |
35743 次 |
| 最近记录: |