将nginx配置成service服务
- 第1步,配置nginx服务之前先杀掉nginx进程
ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9 2> /dev/null
cat > /lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
chmod +x /usr/lib/systemd/system/nginx.service
systemctl daemon-reload
systemctl start nginx
systemctl status nginx