nginx 命令行启动成功, systemd启动失败

通过一下方式解决问题: https://serverfault.com/questions/759175/nginx-hangs-using-service-nginx-start

 

使用./nginx 启动成功,但是使用systemd配置启动失败,以下是配置文件 :

sudo nano /etc/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target

[Service]
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
KillMode=process
Restart=on-failure
RestartSec=3
PrivateTmp=true

[Install]
WantedBy=multi-user.target

通过 journalctl -ef 跟踪日志

使用systemctl start nginx

发现以下输出:

Registered Authentication Agent for unix-process:24358:1989296 (system bus name :1.68 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Jan 19 15:46:58 i-px256c2u systemd[1]: Started The NGINX HTTP and reverse proxy server.
Jan 19 15:46:58 i-px256c2u systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Jan 19 15:46:58 i-px256c2u polkitd[457]: Unregistered Authentication Agent for unix-process:24358:1989296 (system bus name :1.68, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)

 

解决方法,在service配置文件指定pid文件位置,例如:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target

[Service]
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
KillMode=process
Restart=on-failure
RestartSec=3
PrivateTmp=true

[Install]
WantedBy=multi-user.target

pid文件位置根据自己情况修改

posted @ 2024-01-19 16:01  古德爱迪尔  阅读(213)  评论(0编辑  收藏  举报