Nginx不会在启动时启动,而是手动启动.日志说的像
Nginx: [emerg] host not found in upstream "{some hostname}" in /etc/Nginx/conf.d/some_site.conf Nginx: configuration file /etc/Nginx/Nginx.conf test Failed Failed to start A high performance web server and a reverse proxy server. Nginx.service: Unit entered Failed state. Nginx.service: Failed with result 'exit-code'.
似乎在启动时dns尚未就绪,Nginx正在尝试查找我作为反向代理的主机名.
经过一些研究后发现systemd使用下面的文件来启动Nginx
/lib/systemd/system/Nginx.service
Ubuntu 15.04,Ubuntu 15.10上的文件,甚至Nginx网站本身都说要使用After行,如下所示
After=network.target
这使得一个人认为网络应该已经准备好了.但是,我找到了链接http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
network.target has very little meaning during start-up. It only indicates that the network management stack is up after it has been reached.
这个链接继续说
network-online.target is a target that actively waits until the nework is “up”,where the definition of “up” is defined by the network management software.
所以我改变了After的用法
After=network-online.target
现在Nginx在启动时启动良好.我没有声称这是完全正确的解决方案,因为有可能使用不同的After目标,这在某些其他方面会更正确,但这似乎适用于最后几次重新启动.