39

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

4 Answers 4

64

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
8
  • 3
    A perfect answer. Apr 11, 2013 at 3:00
  • For my info, why/would we need this if we have an appropriately-configured /etc/init/nginx.conf?
    – msanford
    Jun 27, 2014 at 15:38
  • first try this sudo service nginx stop sudo service nginx start, if this not working then try above steps. Oct 10, 2014 at 10:23
  • The url does not return the script Mar 6, 2015 at 16:22
  • 1
    I have installed nginx in /etc directory (/etc/nginx), i have updated script path also: PATH=/etc/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/etc/nginx/sbin/nginx but it's not working, do i have to change anything else?
    – Adan
    Aug 30, 2015 at 11:54
5

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

1

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
0

Some files required by NGINX may have been deleted or misplaced.

This may help

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.