7

Is there a way to make Nginx 1.11 bind to a specific interface regardless of the IP address?

I've got a home gateway to an ISP provider; it uses DHCP client to obtain its dynamic IP address. I do not know what that IP address is at NGINX configuration time.

Surely, there must be a way to make such a fine HTTP server bind to a specific network interface? I know that Apache can.

4

1 回答 1

8

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

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

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

include /path/to/some/file;

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

于 2016-09-16T17:20:50.407 回答