无论 IP 地址如何,NGINX 都绑定到特定的网络接口

Joh*_*ene 6 nginx network-security

有没有办法让 Nginx 1.11 绑定到特定的接口而不管 IP 地址?

我有一个通往 ISP 提供商的家庭网关;它使用 DHCP 客户端来获取其动态 IP 地址。我不知道 NGINX 配置时那个 IP 地址是什么。

当然,一定有办法让这么好的 HTTP 服务器绑定到特定的网络接口吗?我知道 Apache 可以。

Ale*_*sky 6

编辑启动序列以运行捕获接口 IP 地址的命令或脚本,并将其以listen <ip>:80您想要的格式或任何端口写入文件:

echo "listen $(ip -o -4 a s eth0 | awk '{ print $4 }' | cut -d/ -f1):80;" > /path/to/some/file
Run Code Online (Sandbox Code Playgroud)

然后让你的 nginx 配置包含该文件:

include /path/to/some/file;
Run Code Online (Sandbox Code Playgroud)

显然,您需要确保在 nginx 启动之前进行 IP 捕获。

  • 是的。检查 Nginx 机器代码表明它不能绑定到特定接口。仅用直筒外套设置就减少了优质产品,这是多么令人遗憾的耻辱。 (3认同)