Launch Nginx on startup

I was able to install and run nginx, and passenger but i'm not able to have nginx come up whenever i reboot my server. To start the nginx process i just type in sudo /opt/nginx/sbin/nginx. From my understanding anything i put in /etc/init.d with ubuntu hardy will be execute. Does anyone know the command that will mimic this command line call?

sudo /opt/nginx/sbin/nginx


To start nginx on boot: sudo systemctl enable nginx (doesn't start it immediately)

To start nginx: sudo systemctl start nginx


Thanks for the info, if someone wants step by step instructions. Go to /etc/init.d and run sudo nano nginx-passenger.sh, then paste in this code:

#!/bin/bash
# this script starts the nginx process attached to passenger
sudo /opt/nginx/sbin/nginx

save and exit. Make the file executable by typing sudo chmod +x /etc/init.d/nginx-passenger.sh. You can test to see if the script works by typing sudo /etc/init.d/nginx-passenger.sh this will run all the code in the script. Verify that it launches nginx before continuing.

Then run sudo update-rc.d nginx-passenger.sh defaults while still in the /etc/init.d directory. Once all of this is in place, reboot your server and ngnix should now be automatically spawned on startup


/etc/init.d is just the location for the start up scripts to live. But having a script there doesn't do anything automatically.

The init system uses the symbolic links in the /etc/rc#.d directories to the scripts in the /etc/init.d folder. The name of the symbolic link needs to start with an S to run the script with the start option and K to run the stop option followed by a priority number and then the name of the script.

See the following for more info
/etc/init.d/README
/etc/rc1.d/README
/etc/rc2.d/README

Alternatively you can put your command you want to run into the /etc/rc.local script which is run after the system boots and finishes executing all the scripts in the /etc/rc2.d/ folder.