centos7 nginx开机自启
时间: 2023-12-11 09:33:46 浏览: 121
在CentOS 7中,可以通过systemd来实现nginx的开机自启。具体步骤如下:
1.创建一个名为nginx.service的文件,路径为/etc/systemd/system/,并将以下内容复制到文件中:
```shell
[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/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=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
```
2.保存文件并退出编辑器。
3.使用以下命令重新加载systemd管理器配置:
```shell
systemctl daemon-reload
```
4.使用以下命令将nginx服务添加到系统启动项中:
```shell
systemctl enable nginx.service
```
5.使用以下命令启动nginx服务:
```shell
systemctl start nginx.service
```
现在,nginx服务已经设置为在CentOS 7启动时自动启动。
阅读全文
相关推荐
















