Tarrioin
By:
Tarrioin

what (code=exited, status=1/FAILURE) ? service nginx status

February 11, 2017 32.8k views
Nginx Ubuntu 16.04

I just found an error in the state of nginx.
This error does not prevent anything.
It does not give me problems.
Everything is started correctly.
Nginx -t
It did not return any syntax errors.

I only see it in the nginx status sale.
Service nginx status.
Or
Systemctl status nginx

Error:

systemctl status nginx

  • nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2017-02-11 20:55:04 UTC; 5min ago Process: 25343 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE) Process: 25710 ExecStart=/usr/sbin/nginx -g daemon on; masterprocess on; (code=exited, status=0/SUCCESS) Process: 25706 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; masterprocess on; (code=exited, status=0/SUCCESS) Main PID: 25715 (nginx) Tasks: 2 Memory: 2.0M CPU: 49ms CGroup: /system.slice/nginx.service |-25715 nginx: master process /usr/sbin/nginx -g daemon on; master_process on `-25720 nginx: worker process

Feb 11 20:55:04 Singapore-ap-southeast systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 11 20:55:04 Singapore-ap-southeast systemd[1]: nginx.service: PID 25363 read from file /run/nginx.pid does not exist or is a zombie.
Feb 11 20:55:04 Singapore-ap-southeast systemd[1]: Started A high performance web server and a reverse proxy server.

3 Answers

If nginx -t doesn't return anything, I would verify Nginx error log. By default, it should be located in /var/log/nginx/error.log. You can open it with any text editor:

  • sudo nano /var/log/nginx/error.log

Can you find there something suspiciously?

Second log which can you take a look is Syslog:

  • sudo nano /var/log/syslog

Try to find nginx logs and see what they say.
Did you changed anything before this happened?

  • Thanks for your help.
    I just had the files published.
    They are huge and I do not know what I'm looking for.
    After solving it I delete them leaving only I publish the error in case someone else helps.

    • This is last error it errored:

      Feb 11 19:28:54 Singapore-ap-southeast systemd[1]: Starting A high performance web server and a reverse proxy server...
      Feb 11 19:28:54 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
      Feb 11 19:28:54 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
      Feb 11 19:28:55 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
      Feb 11 19:28:55 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
      Feb 11 19:28:55 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
      Feb 11 19:28:55 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
      Feb 11 19:28:56 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
      Feb 11 19:28:56 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
      Feb 11 19:28:56 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
      Feb 11 19:28:56 Singapore-ap-southeast nginx[18199]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
      Feb 11 19:28:57 Singapore-ap-southeast nginx[18199]: nginx: [emerg] still could not bind()
      Feb 11 19:28:57 Singapore-ap-southeast systemd[1]: nginx.service: Control process exited, code=exited status=1
      Feb 11 19:28:57 Singapore-ap-southeast systemd[1]: Failed to start A high performance web server and a reverse proxy server.
      Feb 11 19:28:57 Singapore-ap-southeast systemd[1]: nginx.service: Unit entered failed state.
      Feb 11 19:28:57 Singapore-ap-southeast systemd[1]: nginx.service: Failed with result 'exit-code'.
      

      Do you have something other running on port 80? If you do, it would block nginx.
      But as I see from last log, it started successfully:

      Feb 11 20:55:02 Singapore-ap-southeast systemd[1]: Starting A high performance web server and a reverse proxy server...
      Feb 11 20:55:02 Singapore-ap-southeast systemd[1]: nginx.service: PID 20404 read from file /run/nginx.pid does not exist or is a zombie.
      Feb 11 20:55:02 Singapore-ap-southeast systemd[1]: Started A high performance web server and a reverse proxy server.
      

      What does sudo systemctl status nginx return? Is it running or not?

      As of nginx logs, check permissions on your /var/www directory.

      2017/02/11 20:35:39 [error] 20371#20371: *2 directory index of "/var/www/" is forbidden, client: 127.0.0.1, server: _, request: "HEAD / HTTP/1.1", host: "localhost"
      

      Above error is happening a lot, it could indicate that permission on /var/www are miss set.
      Make sure owner:group is set to root:root, or www-data:www-data if you require writing via web app. Also, permissions should be set to 755.
      To check it you can execute ls -l /var and find there www, and for inside of /var/www do the ls -l /var/www. There you can see permissions and owner:group.
      Commands to set correct permissions are:

      • sudo chown -R root:root /var/www
      • sudo chmod 755 /var/www

      Don't forget to delete logs, I think you can do it now. Deletion could be locked after some time.

Error resulted.

I simply did:
Service nginx stop

And then start with the new system:
Systemctl start nginx

And now he devoured me.

* nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2017-02-11 21:41:00 UTC; 1min 43s ago
  Process: 20928 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 20941 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 20938 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 20944 (nginx)
    Tasks: 2
   Memory: 2.0M
      CPU: 22ms
   CGroup: /system.slice/nginx.service
           |-20944 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           `-20945 nginx: worker process                           

Feb 11 21:41:00 Singapore-ap-southeast systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 11 21:41:00 Singapore-ap-southeast systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Feb 11 21:41:00 Singapore-ap-southeast systemd[1]: Started A high performance web server and a reverse proxy server.

The only bad thing I see is the "PID from file /run/nginx.pid: Invalid argument"
But all functional.

  • PID from file /run/nginx.pid: Invalid argument is not a big problem. It's some bug that's even confirmed. If you want to read more about it, you can refer to Launchpad bug tracker.

    • Thank you.
      If I was already reading.
      Since it is not a real problem I will not pay attention.

      Well with all this I already have a cluster of three nodes with galera, mariadb, php7, nginx, monit, memcached, route 53 with server change due to failure and client latency.

      I will take a snapshot of all the servers and continue with the last step.

      Create an automatic backup of the database and upload it automatically to Amazon S3.

For whoever has the problem. Fix it by uninstalling all Nginx and adding the new version directly from the Nginx url. That has no error and is a more up to date version of the digitalocean

Have another answer? Share your knowledge.