Trying to start nginx on VPS, I get "nginx: unrecognized service"

Following the How to install rails and nginx with passenger on Ubuntu tutorial from DigitalOcean.com, the seventh step manually starts nginx:

sudo service nginx start

but fails with the following error:

nginx: unrecognized service

The nginx: unrecognized service error means the startup scripts need to be created.
Fortunately the startup scripts have already been written.

We can fetch them with wget and set them up following these steps:

# Download nginx startup script
wget -O init-deb.sh https://www.linode.com/docs/assets/660-init-deb.sh

# Move the script to the init.d directory & make executable
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx

# Add nginx to the system startup
sudo /usr/sbin/update-rc.d -f nginx defaults

Now we can control nginx using:

sudo service nginx stop 
sudo service nginx start 
sudo service nginx restart
sudo service nginx reload

It can also mean that the permissions are wrong on the init script, e.g. you do not have the execute bit set


for me I was running vagrant to setup nginx and forgot to put in the -y so the nginx install had not completed. So I just needed to ensure it was fine in my Vagrant init.sh bash file

sudo apt-get install -y nginx
sudo service nginx restart