"sudo service nginx start" fails but "sudo nginx" works - can't figure out why

I came across this similar situation and it was because the port was already used by another service.

How I found it out ?

Try running

sudo nginx

rather than starting it as a service and it should display the error message.


This won't be a very satisfying or popular answer but it's what I found.

It seems that the upstart mechanism is very sensitive to external conditions that go beyond what nginx itself was concerned about.

Since I had a stopgap measure of starting nginx outside upstart, I continued with updating my server. When it came to restarting nginx to make sure it was using the current environment, I used "sudo service nginx restart" to stop the current one and then manually entered the start command that failed in the upstart script(the stop worked it was the start that fails). After doing this for a while and updating subdomains and files to be served along with other small things, abruptly. the "sudo service nginx restart" worked. At no point had the manual start of nginx or the "sudo service nginx restart" commands put out any errors/warnings that I could find.

All I can think of is that there must have been some condition that was below the threshold for putting out any type of error or warning that bothered upstart, but not nginx. While it was enough to make it fail, it didn't bother it enough to put out any actual message as to why it was failing. Arrgh!