iptables 没有将任何流量转发到 HAProxy

iptables are not forwarding any traffic to HAProxy

我遇到了以下问题:

我的路由器 (FritzBox) 设置为将所有传入流量(通过暴露的主机)转发到我的服务器 (192.168.0.1)

我在 lxc 容器 (192.168.0.100) 上有一个 HAProxy 运行ning,它正在将 http 流量转发到其他一些 lxc 容器 - 这工作正常。

问题是,当我 运行 以下命令(curl 到我的代理)时,我得到了正确的答案:

curl --verbose --header 'Host: myrealdomain.tld' http://192.168.0.100


* Rebuilt URL to: http://192.168.0.100/
*   Trying 192.168.0.100...
* Connected to 192.168.0.100 (192.168.0.100) port 80 (#0)
> GET / HTTP/1.1
> Host: murdr.eu
> User-Agent: curl/7.47.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 503 Service Unavailable
< Cache-Control: no-cache
< Connection: close
< Content-Type: text/html
<
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>

* Closing connection 0

但是当运行使用相同的命令(curl 到我的服务器,应该将流量转发到代理)时,我无法连接,因为连接被拒绝:

curl --verbose --header 'Host: myrealdomain.tld' http://192.168.0.1


* Rebuilt URL to: http://192.168.0.1/
*   Trying 192.168.0.1...
* connect to 192.168.0.1 port 80 failed: Connection refused
* Failed to connect to 192.168.0.1 port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 192.168.0.1 port 80: Connection refused

(myrealdomain.tld换成了我的真实域名,这里为了安全我改了)

这是我的 iptables(我测试了各种东西,然后经常刷新,但没有任何效果)。

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

iptables -L -t nat

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (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

iptables -S(如 Luke Mlsna 所问)

-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

apache2 在我的服务器上 运行ning。但我在设置代理容器和 iptables 后删除了它。

这里是开放的端口,没有80端口

lsof -i -P -n


COMMAND    PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-n  938 systemd-network   19u  IPv6  33240      0t0  UDP [fe80::f64d:30ff:fe66:8010]:546
systemd-r  980 systemd-resolve   12u  IPv4  22967      0t0  UDP 127.0.0.53:53
systemd-r  980 systemd-resolve   13u  IPv4  22968      0t0  TCP 127.0.0.53:53 (LISTEN)
nmbd      1108            root   15u  IPv4  22474      0t0  UDP *:137
nmbd      1108            root   16u  IPv4  22475      0t0  UDP *:138
nmbd      1108            root   17u  IPv4  38559      0t0  UDP 192.168.0.1:137
nmbd      1108            root   18u  IPv4  38560      0t0  UDP 192.168.1.255:137
nmbd      1108            root   19u  IPv4  38561      0t0  UDP 192.168.0.1:138
nmbd      1108            root   20u  IPv4  38562      0t0  UDP 192.168.1.255:138
sshd      1200            root    3u  IPv4  25135      0t0  TCP *:22 (LISTEN)
sshd      1200            root    4u  IPv6  25137      0t0  TCP *:22 (LISTEN)
lxd       1273            root   13u  IPv6  27850      0t0  TCP *:8443 (LISTEN)
mysqld    1501           mysql   39u  IPv4  27943      0t0  TCP 127.0.0.1:3306 (LISTEN)
smbd      3606            root   32u  IPv6  37803      0t0  TCP *:445 (LISTEN)
smbd      3606            root   33u  IPv6  37804      0t0  TCP *:139 (LISTEN)
smbd      3606            root   34u  IPv4  37805      0t0  TCP *:445 (LISTEN)
smbd      3606            root   35u  IPv4  37806      0t0  TCP *:139 (LISTEN)
sshd      6140            root    3u  IPv4  59450      0t0  TCP 192.168.0.1:22->192.168.0.43:62339 (ESTABLISHED)
sshd      6350         unicorn    3u  IPv4  59450      0t0  TCP 192.168.0.1:22->192.168.0.43:62339 (ESTABLISHED)

我现在将我的流量从我的路由器直接发送到 HAProxy,中间没有服务器。 努力工作!