通过 systemd 管理自编译的 Nginx

use*_*600 1 nginx systemd

我从源代码编译了 Nginx,现在我想通过 systemd 来管理它systemctl start,stop,restart,reload,enable nginx.service。我需要做什么才能启用它?

Esa*_*nen 6

您需要将NGINX systemd 服务文件添加到/lib/systemd/system/nginx.service.

对于您自己的 Nginx 实例(与您的发行版提供的实例相比)/etc/systemd/system/nginx.service可能是正确的位置。/lib/systemd/system/nginx.service当使用systemctl enable nginx.service(或reenable)启用时,它也会覆盖。

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/sbin/nginx -t
ExecStart=/usr/local/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

您可能需要根据您编译的 Nginx 所在的位置更改路径。在这里,我假设它在/usr/local/sbin/nginx.