突然发现重启服务器后Systemd enable Nginx配置的自启无法启动，日志文件报错误
nginx: [emerg] host not found in upstream "mydomain.com" in /etc/nginx/sites-enabled/test.conf:33
after installing Nginx on a new system I have some issues when rebooting the system. Nginx is unable to start and throws this error:
nginx: [emerg] host not found in upstream “mydomain.com” in /etc/nginx/sites-enabled/test.conf:33
When I try to ping mydomain.com it works without any issues, I also can start the Nginx service manually. Is it possible that Nginx tries to start before the system can resolve host names?
What distro are you using? I encountered this issue with the nginx package in Debian Stretch. It bundled a systemd service file for nginx that had an
After=network.targetdependency, so it tried to start the nginx service before the network was fully available/working. Nginx then wasn’t able to resolve the upstream domain into an IP address and failed to start.
After overriding the service file so it has
After=network-online.targetdependency instead, nginx was able to start upon reboot reliably.