Centos8 nginx开机自启动配置

第一步进入文件夹内

cd /lib/systemd/system

第二步编辑nginx.service文件键入以下内容

vim nginx.service

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

[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t #nginx安装目录
ExecStart=/usr/local/nginx/sbin/nginx #nginx安装目录
ExecReload=/usr/local/nginx/sbin/nginx -s reload #nginx安装目录
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

开机自启动设置

# systemctl start nginx.service  启动nginx服务

# systemctl stop nginx.service           停止服务

# systemctl restart nginx.service       重新启动服务

# systemctl list-units --type=service    查看所有已启动的服务

# systemctl status nginx.service          查看服务当前状态

# systemctl enable nginx.service          设置开机自启动

# systemctl disable nginx.service        停止开机自启动


你可能感兴趣的:(Centos8 nginx开机自启动配置)