将nginx配置成service服务

  • 第1步,配置nginx服务之前先杀掉nginx进程
ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9 2> /dev/null
  • 第2步,创建nginx服务的配置文件
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
  • 第3步,重新加载服务
chmod +x /usr/lib/systemd/system/nginx.service
systemctl daemon-reload
  • 第4步,测试一下服务启动
systemctl start nginx
systemctl status nginx
Copyright © www.sqlfans.cn 2024 All Right Reserved更新时间: 2023-09-25 17:33:45

results matching ""

    No results matching ""