无法在运行Debian的Google Compute Engine上打开端口8080 [英] Can't open port 8080 on Google Compute Engine running Debian

查看:107
本文介绍了无法在运行Debian的Google Compute Engine上打开端口8080的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个简单的Python http服务器,该服务器使用微型实例在端口8080上显示"hello world".我也有4个龙卷风实例在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()

解决方案

您的网络是否具有相应的防火墙规则?请按照以下步骤创建它.

  1. 转到开发人员控制台,然后单击相应的项目.

  2. 点击计算"

  3. 点击网络"

  4. 单击相应网络的名称.您可以通过单击计算引擎"部分下的虚拟机实例"或使用以下命令来查看您的实例在哪个网络中:

    gcloud compute instances describe <instance> | grep "network:" | awk -F/ '{print $(NF)}'

  5. 在防火墙规则"部分下,单击新建"

  6. 输入防火墙规则的名称,并在"Protocols&端口的类型:tcp:8080

  7. 保存规则

之后,您应该可以访问HTTP服务器.

否则,您可以尝试使用以下命令查看您的计算机是否在该端口中接收到SYN TCP数据包:

希望有帮助

I am trying to run a simple Python http server that displays "hello world" on port 8080 using a micro instance. I also have 4 instances of Tornado running behind Nginx. Connecting to Nginx/Tornado on port 80 is not a problem.

I have added port 8080 to my firewall settings, and ensured port 8080 is open and listening on the server but no matter what I do, my connection is always refused. I have tried connecting using browsers, telnet and wget and every single connection is refused.

Here is the output of 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

Here is my iptables list

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

Here is the Python script I am using:

#!/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()

解决方案

Does your network have the corresponding firewall rule? Follow the next steps to create it.

  1. Go to the Developers Console and click on the corresponding project.

  2. Click on 'Compute'

  3. Click on 'Networks'

  4. Click on the name of the corresponding network. You can see in which network is your instance clicking on 'VM instances' under the 'Compute Engine' section or with the command:

    gcloud compute instances describe <instance> | grep "network:" | awk -F/ '{print $(NF)}'

  5. Under the Firewall rules section, click 'Create new'

  6. Enter a name for the firewall rule and in the field 'Protocols & ports' type: tcp:8080

  7. Save the rule

After that, you should be able to access your HTTP server.

Otherwise you can try to see if your machine receives the SYN TCP packets in that port with the command: sudo tcpdump -i eth0 port 8080

Hope it helps

这篇关于无法在运行Debian的Google Compute Engine上打开端口8080的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆