将Nginx配置成系统服务

创建服务脚本

1
vi /usr/lib/systemd/system/nginx.service

服务脚本内容
路径需自行修改,对应本地的nginx路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重新加载系统服务

1
systemctl daemon-reload

启动服务

1
systemctl start nginx

开机启动

1
systemctl enable nginx

将Nginx配置成系统服务
http://lhystutest.top/2023/02/08/Linux/基础操作/将nginx配置成系统服务/
作者
lhy
发布于
2023年2月8日
许可协议