CentOS8 nginx: [emerg] bind() failed (99: Cannot assign requested address)

CentOS8 nginx: [emerg] bind() failed (99: Cannot assign requested address)

2020 年 1 月 17 日 我在两台独立的服务器上安装了 CentOS 8,一台是云服务器,另一台是专用服务器。在这两种情况下,Nginx 都不会在服务器重启时自动启动。 /var/log/boot.log 的两个指示网络管理器在 Nginx 之前启动,但它们显然 运行 并行并且 Nginx 在网络初始化之前激活。这导致 Nginx 出错 'Cannot assign requested address'。如果我在系统启动后手动启动 Nginx,它会毫无问题地进行初始化。我能够确定一个解决方案并将 post 作为答案,以便我可以将其标记为已解决。由于它在两个完全不相关的安装上是一致的,我相信其他人也会有同样的问题并正在寻找我没有找到的答案。

此更改在两台服务器上对我都有效:
编辑 /usr/lib/systemd/system/nginx.service 文件

更改默认值:
[单位]
Description=nginx HTTP 和反向代理服务器
after=network.target remote-fs.target nss-lookup.target

收件人:
[单位]
Description=nginx HTTP 和反向代理服务器
after=network.target remote-fs.target nss-lookup.target network-online.target
想要=网络-online.target

这会强制Nginx等到网络在线后再启动。

根据在此页面上找到的信息:
https://unix.stackexchange.com/questions/126009/cause-a-script-to-execute-after-networking-has-started