0

I installed the latest version of nginx (1.0.15) using apt-get from the source listed here: http://nginx.org/en/download.html.

For some reason, nginx isn't starting up automatically when I reboot the server, as I believe it should. /etc/init.d/nginx exists so I can start/stop/restart manually, but any ideas on why it isn't starting automatically? I was under the impression it should right out of the box if installed via apt-get.

Thanks.

Edit: After looking at various logs, I discovered that nginx wasn't starting on startup because I had an ssl server set up without a certificate (haven't added the certificate yet because I haven't yet migrated the domain). Commenting out the ssl server appears to have solved the problem. I presume that when I'm ready to add the certs for the domain the problem won't reappaer - here's hoping :).

As an aside, I was also experiencing a problem that the change above seems to have solved. I have Options -Indexes set in Apache to prevent directory browsing, and for most directory paths I would get the "Forbidden" message from Apache. For some, however, if I omitted the trailing slash in the path, the server wouldn't respond with the Forbidden message, or any message at all. I thought I must have some setting in nginx or apache2 that was causing this, but couldn't identify one. Now the problem has disappeared with the above change. Can't explain it.

user101570
  • 77
  • 8

2 Answers2

1

The script in /etc/init.d doesn't actually do anything unless it's symlinked in /etc/rc2.d (or whatever the startup runlevel is).

To do this, run sudo update-rc.d nginx defaults which will create the necessary symlinks for automatically starting up the service after boot. You can verify by running ls -l /etc/rc?.d/*nginx before and after. The "after" will show symlinks to the script in /etc/init.d.

cjc
  • 24,916
  • 3
  • 51
  • 70
  • I did as you suggested and can verify the symlinks exist. But nginx still isn't starting on reboot. – user101570 Apr 17 '12 at 14:32
  • Does it start when you run `/etc/ini.d/nginx start`? Do you have Apache installed already, and it's starting up before nginx and sitting on port 80? – cjc Apr 17 '12 at 14:45
  • Yes, I'm able to execute /etc/init.d/nginx start|stop|restart with no problems. Just won't start on reboot. – user101570 Apr 17 '12 at 15:24
  • Anything in, say, /var/log/boot.log or /var/log/nginx during the boot? – cjc Apr 17 '12 at 15:26
  • Fixed. I'm accepting this answer for your suggestion to look at logs, and have edited my question to provide the solution. – user101570 Apr 19 '12 at 19:50
0

Try to add nginx script to be started at startup:

update-rc.d nginx defaults

Alexander
  • 774
  • 2
  • 11
  • 20
  • Thanks, but didn't work. The symlinks exist but that hasn't solved the problem. – user101570 Apr 17 '12 at 14:33
  • What there in logs? If script won't start, you'll see the reason in both system log and nginx log. And please check if you're able to start nginx with exactly `/etc/init.d/nginx start`, so update-rc.d create right links. – Alexander Apr 17 '12 at 14:55
  • And have a look what's on 80/tcp port right after server reboot? If you have another http server (Apache or any other) then nginx can't bind to 80 port and won't work. Then you need to disable another http server. – Alexander Apr 17 '12 at 14:58
  • Hmm... I am using nginx as a reverse proxy to apache2, but apachd2 ports.conf is set to only listen on a different port from 80. – user101570 Apr 17 '12 at 15:13
  • Then it should work. What logs says, anyway? – Alexander Apr 17 '12 at 15:39
  • If you're use nginx as reverse proxy, may this be useful to get rid of apache at all and set up nginx + php-fpm, which saves you memory and CPU cycles but you'll need to change nginx config to accommodate .htaccess configs (if any) – Alexander Apr 17 '12 at 15:47
  • Thanks Alexander, I considered php-fpm, but have decided to wait for php6 for this particular application. – user101570 Apr 19 '12 at 20:02
  • But why do you think php6 will solve that? – Alexander Apr 20 '12 at 05:47
  • By the way, you can try [LiteSpeed Web Server](http://www.litespeedtech.com/overview.html) - pretty fast, while fully 'understand' .htaccess etc, but [free](http://www.litespeedtech.com/litespeed-web-server-editions.html) edition is for not very heavy loaded sites. For your situation this may be good idea anyway: you'll have more requests-per-seconds served on the same hardware while not care for having split servers scheme. – Alexander Apr 20 '12 at 05:56