RickL
By:
RickL

Can't start Nginx - Job for nginx.service failed

August 12, 2015 102.2k views
Nginx LEMP Ubuntu

Hello,

This is my fist droplet and I've followed all the steps for the initial server setup with Ubuntu, how to setup a firewall with ufw, I've installed Nginx and it worked. Then I've installed MariaDb and started it, everything was ok, and after I've installed PHP I've followed "Step Four — Configure Nginx to Use our PHP Processor" from here: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04
(although I have Ubuntu 15.04 x64 on my droplet)
Did "sudo nano /etc/nginx/sites-available/default" and put the same setup it is in their example, but after "sudo service nginx restart" couldn't restart the Nginx, I'm getting:

myusername@droplet1:~$ sudo service nginx restart
Job for nginx.service failed. See "systemctl status nginx.service" and "journalctl -xe" for details.
myusername@droplet1:~$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2015-08-12 20:16:25 CEST; 23s ago
  Process: 24221 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 17425 (code=exited, status=0/SUCCESS)
myusername@droplet1:~$ journalctl -xe
Hint: You are currently not seeing messages from other users and the system.
      Users in the 'systemd-journal' group can see all messages. Pass -q to
      turn off this notice.
--
-- The start-up result is done.
Aug 12 18:43:25 droplet1.mysite.com systemd[15692]: Starting Shutdown.
-- Subject: Unit UNIT has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit UNIT has begun starting up.
Aug 12 18:43:25 droplet1.mysite.com systemd[15692]: Starting Exit the Session..
-- Subject: Unit UNIT has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit UNIT has begun starting up.
Aug 12 18:43:25 droplet1.mysite.com systemd[15692]: Received SIGRTMIN+24 from P
Aug 12 18:43:34 droplet1.mysite.com systemd[16747]: Trying to run as user insta
Aug 12 18:43:34 droplet1.mysite.com systemd[16748]: pam_unix(systemd-user:sessi
Aug 12 18:46:06 droplet1.mysite.com sudo[16790]: pam_unix(sudo:auth): authentic
Aug 12 19:40:45 droplet1.mysite.com systemd[21873]: Trying to run as user insta
Aug 12 19:41:20 droplet1.mysite.com sudo[21907]: pam_unix(sudo:auth): authentic
Aug 12 20:04:23 droplet1.mysite.com systemd[24038]: Trying to run as user insta
Aug 12 20:09:59 droplet1.mysite.com systemd[24109]: Trying to run as user insta
Aug 12 20:15:47 droplet1.mysite.com systemd[24180]: Trying to run as user insta
lines 1142-1164/1164 (END)

Anyone have an idea about what happens?

Thanks!

3 comments
9 Answers

Glad to hear you got it working!

In the future, here's something that might come in useful. You can check the syntax of Nginx's configuration files by running:

  • nginx -t -c /etc/nginx/nginx.conf

The error output will give you a hint at what the problem is as well as the line number.

Heres the bug. Its fixed but not showing in Digitaocean repos fix.
You can manually edit this to work.
https://github.com/webmin/webmin/issues/206

If you miss the semicolon symbol ";" at the end of any statement, you may not get the error when trying to start / restart / reload nginx.

Example: Here you will get the error, as ; is missed on line no 3.

  • server {
    location / {
    proxy_pass http://localhost:8080
    }

            location ~ \.(gif|jpg|png)$ {
                    autoindex on;
                    root /data/images;
            }
    }*
    

I am getting below output
nginx -t -c /etc/nginx/nginx.conf
nginx: [emerg] PEMreadbioX509AUX("/etc/pki/tls/certs/logstash-forwarder.crt") failed (SSL: error:0906D06C:PEM routines:PEMreadbio:no start line:Expecting: TRUSTED CERTIFICATE)
nginx: configuration file /etc/nginx/nginx.conf test failed

I dont know what have I missed.

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2016/09/23 03:28:01 [warn] 16707#16707: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2016/09/23 03:28:01 [emerg] 16707#16707: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

This is my output after running
nginx -t -c /etc/nginx/nginx.conf

I am also getting same kind of error after trying to restart Nginx

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/var/lib/nginx/body" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed

hello i have some problem with Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.

nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Sun 2016-10-30 04:28:58 EDT; 13min a go
Process: 26460 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE)
Process: 26395 ExecReload=/usr/sbin/nginx -g daemon on; masterprocess on; -s reload (code=exited, status=1/FAILURE)
Process: 26092 ExecStart=/usr/sbin/nginx -g daemon on; masterprocess on; (cod e=exited, status=0/SUCCESS)
Process: 26486 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 26095 (code=killed, signal=KILL)

Oct 30 04:28:58 bestdealstodays nginx[26486]: nginx: [emerg] could not build...4
Oct 30 04:28:58 bestdealstodays nginx[26486]: nginx: configuration file /etc...d
Oct 30 04:28:58 bestdealstodays systemd[1]: nginx.service: control process e...1
Oct 30 04:28:58 bestdealstodays systemd[1]: Failed to start A high performan....
Oct 30 04:28:58 bestdealstodays systemd[1]: Unit nginx.service entered faile....
Oct 30 04:42:05 bestdealstodays systemd[1]: Unit nginx.service cannot be rel....
Oct 30 04:42:31 bestdealstodays systemd[1]: Unit nginx.service cannot be rel....
Hint: Some lines were ellipsized, use -l to show in full.

-- Logs begin at Mon 2016-10-03 17:54:02 EDT, end at Sun 2016-10-30 04:42:31 EDT. --
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyShutdown ::= { netSnmpNotifi
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyRestart ::= { netSnmpNotific
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laErrMessage ::= { laEntry 101 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laErrorFlag ::= { laEntry 100 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laLoadFloat ::= { laEntry 6 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laLoadInt ::= { laEntry 5 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laConfig ::= { laEntry 4 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laLoad ::= { laEntry 3 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laNames ::= { laEntry 2 }
Oct 30 04:42:31 bestdealstodays php5-fpm[26603]: Cannot adopt OID in UCD-SNMP-MIB: laIndex ::= { laEntry 1 }

what should i do? thx for your help

Have another answer? Share your knowledge.