如何把nginx加入到systemctl 里启动
时间: 2023-08-09 12:05:03 浏览: 216
要将Nginx添加到systemctl中以在系统启动时自动启动,请按照以下步骤操作:
1. 打开Nginx配置文件 `/etc/systemd/system/nginx.service`。
1.1 如果该文件不存在,则创建它。
1.2 在该文件中添加以下内容:
```
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
```
2. 保存并关闭该文件。
3. 运行以下命令将Nginx服务添加到systemctl中:
```
sudo systemctl daemon-reload
sudo systemctl enable nginx
```
4. 现在,您可以通过以下命令启动、停止和重新启动Nginx服务:
```
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
```
阅读全文
相关推荐


















