4

Every time I turn on my computer my nginx is not activated:

● 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 Qui 2017-07-27 07:11:02 BRT; 59s ago
  Process: 1006 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Jul 27 07:11:01 note-gui systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 27 07:11:02 note-gui nginx[1006]: nginx: [emerg] host not found in upstream "localhost" in /etc/nginx/sites-enabled/default:27
Jul 27 07:11:02 note-gui nginx[1006]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jul 27 07:11:02 note-gui systemd[1]: nginx.service: Control process exited, code=exited status=1
Jul 27 07:11:02 note-gui systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Jul 27 07:11:02 note-gui systemd[1]: nginx.service: Unit entered failed state.
Jul 27 07:11:02 note-gui systemd[1]: nginx.service: Failed with result 'exit-code'.
~

If i do:

sudo systemctl restart nginx

it works fine, but I have to do that every time I start my Ubuntu.

How can I fix this problem so I don't have to restart nginx every time? I use Ubuntu 16.04.

  • Add to /lib/systemd/system/nginx.service the parameter Restart=always – Ziazis Jul 27 '17 at 10:18
4

The service runs nginx -t (test) before starting the server and this threw up an error:

host not found in upstream "localhost" in /etc/nginx/sites-enabled/default:27

That means you're making a reference to localhost, probably as part of a proxy_pass directive (just guessing) on line 27 of /etc/nginx/sites-enabled/default. And Nginx can't resolve it.

This might be cause for broader concern, but the most simple way around this is to just replace localhost with 127.0.0.1.

  • Still interesting though, haven't used nginx myself in awhile. But that means it is started before the host can lookup himself? So adjusting the start order would be probably also usefull to start it later, since like he said after he manually restarts it, it works without issues. – Ziazis Jul 27 '17 at 10:25
  • perfect awnser, i just change localhost to 0.0.0.0 , restart and works fine, my mistake don't read the msg error – Guilherme Lima Jul 27 '17 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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