我正在尝试为我的 Web 服务器和应用程序服务器运行几个 freebsd jail,它们正在运行 node.js
我有一块网卡(igb0
),上面有一个自定义环回接口(lo666
),我为其创建了 3 个别名,下面是我的部分/etc/rc.conf
dumpdev="AUTO"
zfs_enable="YES"
sshd_enable="YES"
local_unbound_enable=yes
ifconfig_igb0="inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255"
# Custom loopback interface
cloned_interfaces="lo666"
ifconfig_lo666_alias0="inet 10.6.6.6 netmask 255.255.255.255"
ifconfig_lo666_alias1="inet 10.6.6.7 netmask 255.255.255.255"
ifconfig_lo666_alias2="inet 10.6.6.8 netmask 255.255.255.255"
# Default router
defaultrouter="192.168.1.254"
我/etc/pf.conf
有这个
### Interfaces ###
ExtIf ="igb0"
IntIf ="lo666"
### Hosts ###
IP_PUB ="192.168.1.1"
IP_JAIL = "{10.6.6.6, 10.6.6.7, 10.6.6.8}"
IP_JAIL_WWW = "10.6.6.6"
IP_JAIL_DBS = "10.6.6.7"
IP_JAIL_APP = "10.6.6.8"
NET_JAIL="10.6.6.0/24"
### Ports ###
PORT_WWW="{80,443}"
PORT_NODE="{1337,8080}"
scrub in all
# nat all jail traffic
nat pass on $ExtIf from $NET_JAIL to any -> $IP_PUB
# WWW
rdr pass on $ExtIf proto tcp from any to $IP_PUB port $PORT_WWW -> $IP_JAIL_WWW
rdr pass on $IntIf proto tcp from any to $IP_JAIL_WWW port $PORT_NODE -> $IP_JAIL_APP
所以跑
# pfctl -sn
nat pass on igb0 inet from 10.6.6.0/24 to any -> 192.168.1.1
rdr pass on igb0 inet proto tcp from any to 192.168.1.1 port = http -> 10.6.6.6
rdr pass on igb0 inet proto tcp from any to 192.168.1.1 port = https -> 10.6.6.6
rdr pass on lo666 inet proto tcp from any to 10.6.6.6 port = 1337 -> 10.6.6.8
rdr pass on lo666 inet proto tcp from any to 10.6.6.6 port = 8080 -> 10.6.6.8
因此,从 WWW 监狱我可以
root@www:/ # curl http://10.6.6.8:1337
Hello World
并且从 APP jail 中我可以看到 nginx 主页
root@app:/# curl http://10.6.6.6
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>
那么,为什么当我尝试通过浏览器访问时会收到 502 Bad Gateway 错误?这是我的 nginx.conf
server {
server_name web.domain.tld;
location / {
# For Read Requests
proxy_pass http://10.6.6.8:1370;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这是我在 nginx 错误日志中看到的内容
2014/05/23 13:14:44 [error] 92876#0: *1 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream, client: 192.168.1.10, server: web.domain.tld, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.6.6.8:1370/favicon.ico", host: "web.domain.tld"
也许我把它复杂化了,我想要实现的是阻止外部用户使用端口 1337。
任何建议都非常感谢。
答案1
http://10.6.6.8:1337
它不应该http://10.6.6.8:1370
在 nginx.conf 中