Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – 无法连接到127.0.0.1端口80大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有运行nginx服务器(无论哪个服务器): $sudo netstat -tulpn | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4268/nginx tcP6 0 0 :::80 :::* LISTEN 4268/ng
我有运行Nginx服务器(无论哪个服务器):

$sudo netstat -tulpn | grep 80

tcp     0      0 0.0.0.0:80   0.0.0.0:*         LISTEN      4268/Nginx      
  tcP6    0      0 :::80        :::*              LISTEN      4268/Nginx

然后我发送请求到127.0.0.1

$curl -v 127.0.0.1

* Rebuilt URL to: 127.0.0.1/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* connect to 127.0.0.1 port 80 Failed: Connection refused
* Failed to connect to 127.0.0.1 port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused

$telnet localhost 80

Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

好的,在/ etc / hosts中:

127.0.1.1   ubuntu-work
127.0.0.1   localhost

# The following lines are desirable for IPv6 capable hosts 
::1     iP6-localhost iP6-loopBACk
fe00::0 iP6-localnet
ff00::0 iP6-mcastprefix
ff02::1 iP6-allnodes
ff02::2 iP6-allrouters

iptables禁用$sudo iptables -L:

Chain INPUT (policy ACCEPT)
target     prot opt source               desTination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               desTination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               desTination

有趣的是,我可以连接到除127.0.0.1(localhost)之外的任何地址127 … *.而且我也可以连接我的子网ip-address 10.0.2.15.
如果我在服务器配置(例如Listen 88)中将端口80更改为另一端,则可以正常工作.

我尝试了$sudo nmap -sS 127.0.0.1 -p 80并获得了信息 – 80 / tcp关闭,但如果在端口80上运行Nginx服务器怎么可能呢?

Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
PORT   STATE  serviCE
80/tcp closed http

Nmap done: 1 IP address (1 host up) scAnned in 1.12 seconds

loopBACk接口启动:$ifconfig

eth0  Link encap:Ethernet  HWaddr 08:00:27:86:5f:e3  
      inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fe86:5fe3/64 Scope:Link
      UP BroaDCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:588 errors:0 dropped:0 overruns:0 frame:0
      TX packets:616 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:262986 (262.9 KB)  TX bytes:103011 (103.0 KB)

lo    Link encap:Local LoopBACk  
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:276 errors:0 dropped:0 overruns:0 frame:0
      TX packets:276 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:32750 (32.7 KB)  TX bytes:32750 (32.7 KB)

其他iptables表

输出$sudo iptables -t nat -nvL:

Chain PRERoutING (policy ACCEPT 1 packets,40 bytes)
pkts bytes target     prot opt in     out     source               desTination         
0     0 REDIRECT   tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 20559
0     0 REDIRECT   tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443 redir ports 20558

Chain INPUT (policy ACCEPT 1 packets,40 bytes)
pkts bytes target     prot opt in     out     source               desTination         

Chain OUTPUT (policy ACCEPT 1043 packets,65731 bytes)
pkts bytes target     prot opt in     out     source               desTination         
0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            127.0.0.1            tcp dpt:80 redir ports 20559
0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            127.0.0.1            tcp dpt:443 redir ports 20558

Chain POSTRoutING (policy ACCEPT 1043 packets,65731 bytes)
pkts bytes target     prot opt in     out     source               desTination

我没有得到sudo iptables -t mangle -nVL的任何输出,只有版本:iptables v1.4.21

输出sudo iptables -t mangle -nL

Chain PRERoutING (policy ACCEPT)
   target     prot opt source               desTination         

   Chain INPUT (policy ACCEPT)
   target     prot opt source               desTination         

   Chain FORWARD (policy ACCEPT)
   target     prot opt source               desTination         

   Chain OUTPUT (policy ACCEPT)
   target     prot opt source               desTination         

   Chain POSTRoutING (policy ACCEPT)
   target     prot opt source               desTination

如果您对阻止localhost:80有任何想法,请帮助我.

解决方法

没有什么阻止端口80.您只有防火墙NAT规则,它将连接到该端口的路由重定向到其他未打开的端口.
Chain PRERoutING (policy ACCEPT 1 packets,40 bytes)
pkts bytes target     prot opt in     out     source               desTination         
0     0 REDIRECT   tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 redir ports 20559
0     0 REDIRECT   tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443 redir ports 20558

Chain OUTPUT (policy ACCEPT 1043 packets,65731 bytes)
pkts bytes target     prot opt in     out     source               desTination         
0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            127.0.0.1            tcp dpt:80 redir ports 20559
0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            127.0.0.1            tcp dpt:443 redir ports 20558

删除这些规则以解决此问题.

大佬总结

以上是大佬教程为你收集整理的linux – 无法连接到127.0.0.1端口80全部内容,希望文章能够帮你解决linux – 无法连接到127.0.0.1端口80所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。