Home  >  Q&A  >  body text

linux - nginx automatically terminates after starting for a while

nginx is compiled and installed under CentOS 7.3. Use the systemctl start nginx command to start nginx. After the startup is successful, you can access it normally, but you cannot access it after a while. Looking at the background, you find that the nginx process has disappeared. Looking at the error log, you can also No errors. Use the nginx command to start nginx, and there will be no such problem. I am speechless.

/usr/lib/systemd/system/nginx.service

The file is created manually and has the following content:

[Unit]
Description=nginx - high performance web server 
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reopen
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
大家讲道理大家讲道理2713 days ago1224

reply all(1)I'll reply

  • 某草草

    某草草2017-05-16 13:28:37

    I am speechless, point the PID file to

    After

    PIDFile=/var/run/nginx/nginx.pid
    , it turned out normal.

    reply
    0
  • Cancelreply