Nginx配置开机启动
1、编写servie文件
进入/lib/systemd/system目录
[root@localhost system]# pwd
/lib/systemd/system
配置service文件 vi nginx.service
[Unit] Description=nginx service After=network.target [Service] Type=forking ExecStart=/home/zzs/nginx/sbin/nginx ExecReload=/home/zzs/nginx/sbin/nginx -s reload ExecStop=/home/zzs/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
2、验证命令
启动
[root@localhost system]# systemctl start nginx
查看状态
[root@localhost system]# systemctl status nginx ● nginx.service - nginx service Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2023-11-14 21:25:00 EST; 1min 30s ago Process: 1668 ExecStart=/home/zzs/nginx/sbin/nginx (code=exited, status=0/SUCCESS) Main PID: 1669 (nginx) CGroup: /system.slice/nginx.service ├─1669 nginx: master process /home/zzs/nginx/sbin/nginx └─1670 nginx: worker process Nov 14 21:25:00 localhost.localdomain systemd[1]: Starting nginx service... Nov 14 21:25:00 localhost.localdomain systemd[1]: Started nginx service.
停止服务
[root@localhost system]# systemctl stop nginx
重启服务
[root@localhost system]# systemctl restart nginx
设置开机启动
[root@localhost system]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.