65

I am trying to start my nginx server. When I type "$> /etc/init.d/nginx start", I have a message appearing "Starting nginx:", and then nothing happens. There is no error message, and when I check the status of nginx I see that it is not running.

Here is my /etc/nginx/nginx.conf file:

worker_processes  4;
daemon off;

error_log  /home/vincent/tmp/nginx.log;

pid        /home/vincent/tmp/nginx.pid;


events {
    worker_connections  1024;
}


http {
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /home/vincent/tmp/access.log  main;

sendfile        on;

keepalive_timeout  65;

include /etc/nginx/site-enabled/*;

}

And here is my /etc/nginx/sites-available/default file :

server {
  listen       80;
  server_name technical-test.neo9.lan; 

  access_log  /var/log/nginx/technical-test.neo9.lan.log main;

  set $home /home/vincent;

  location / {
    alias $home/neo9/web/app/;
    index  index.html;
  }

  location /api/ {
    rewrite  ^/api/(.*)$  /$1 break;
    proxy_pass http://localhost:1234;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}
10
  • 3
    Did you try service nginx configtest ?
    – Tim Baas
    Jul 25, 2013 at 13:40
  • Using this command give me this answer : "Testing nginx configuration: nginx." Jul 25, 2013 at 13:44
  • 4
    And "sudo nginx -t" gives me : nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful Jul 25, 2013 at 13:46
  • 1
    Did you also try starting nginx with sudo?
    – Tim Baas
    Jul 25, 2013 at 13:47
  • I am always starting it with sudo, otherwise I get an error of permission denied when it tries to acces the error.log file Jul 25, 2013 at 13:49

9 Answers 9

198
+150

First, always sudo nginx -t to verify your config files are good.

I ran into the same problem. The reason I had the issue was twofold. First, I had accidentally copied a log file into my site-enabled folder. I deleted the log file and made sure that all the files in sites-enabled were proper nginx site configs. I also noticed two of my virtual hosts were listening for the same domain. So I made sure that each of my virtual hosts had unique domain names.

sudo service nginx restart

Then it worked.

2
  • 1
    As you(@badmadrad) said I got the following by running sudo nginx -t.but still when I try to restart it fail. ferdinand@ferdinand-desktop:~$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful ferdinand@ferdinand-desktop:~$ sudo service nginx restart * Restarting nginx nginx [fail]
    – Ferdy
    Aug 4, 2014 at 11:36
  • 1
    make sure your site-enabled only has nginx conf files in there. Also make sure there is no port conflict when starting nginx.
    – badmadrad
    Sep 23, 2014 at 17:15
10

You should probably check for errors in /var/log/nginx/error.log.

In my case I did no add the port for ipv6. You should also do this (in case you are running nginx on a port other than 80): listen [::]:8000 default_server ipv6only=on;

7

One case you check that nginx hold on 80 number port in system by default , check if you have any server like as apache or anything exist on system that block 80 number port thats the problem occurred.

1 .You change port number on nginx by this way,

sudo vim /etc/nginx/sites-available/default

Change 80 to 81 or anything,

  1. Check everything is ok by ,

sudo nginx -t

  1. Restart server

sudo service nginx start

  1. Check the status of nginx:

sudo service nginx status

Hope that will work

1
  • 1
    Yeah he is correct , if you have something hosted on port 80 then it will not work. In my case i have hosted apache2 on 80. Try changing the port number as he suggests. Thanks May 12, 2018 at 7:21
5

In your /etc/nginx/nginx.conf file you have:

include /etc/nginx/site-enabled/*;

And probably the path you are using is:

/etc/nginx/sites-enabled/default

Notice the missing s in site.

3

Check the daemon option in nginx.conf file. It has to be ON. Or you can simply rip out this line from config file. This option is fully described here http://nginx.org/en/docs/ngx_core_module.html#daemon

0
1

1. Check for your configuration files by running the aforementioned command: sudo nginx -t.

2. Check for port conflicts. For instance, if apache2 (ps waux | grep apache2) or any other service is using the same ports configured for nginx (say port 80) the service will not start and will fail silently (err... the cousin of my friend had this problem...)

1

If you have apache2 and it's running on the same port[80] that you configed in nginx, you will get error even you get success message on ngingx -t. The correct way is that you have just one webserver, but if you can't do that, use this way:

First stop apache2:

sudo sytemctl stop apache2

Then restart nginx:

sudo service nginx restart

Check the status of apache2 and nginx:

sudo systemctl status apache2

sudo systemctl status nginx
0

I had the exact same problem with my instance. My problem was that I forgot to allow port 80 access to the server. Maybe that's your issue as well?

Check with your WHM and make sure that port is open for the IP address of your site,

2
  • Can you please explain this more
    – Zohab Ali
    Jan 18, 2021 at 18:48
  • It means that to access the adress of the page, you need to allow the traffic to your server instance on port 80 for HTTP. To enable it you can edit inbound rules in security group if you are using AWS. And for Google cluod you can edit this in Firewall. Or similar setting if you are using any other service like digital ocean or Azure or IBM cloud. Aug 30, 2021 at 18:01
0

For what it's worth: I just had the same problem, after editing the nginx.conf file. I tried and tried restarting it by commanding sudo nginx restart and various other commands. None of them produced any output. Commanding sudo nginx -t to check the configuration file gave the output sudo: nginx: command not found, which was puzzling. I was starting to think there were problems with the path.

Finally, I logged in as root (sudo su) and commanded sudo nginx restart. Now, the command displayed an error message concerning the configuration file. After fixing that, it restarted successfully.

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.