Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I went through a tutorial http://craiccomputing.blogspot.com/2010/10/passenger-3-nginx-and-rvm-on-mac-os-x.html and everything was ok. There were no errors.

Nginx with Passenger support was successfully installed.

The Nginx configuration file (/opt/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger
to function correctly.

This installer has already modified the configuration file for you! The
following configuration snippet was inserted:

  http {
      ...
      passenger_root /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.14;
      passenger_ruby /home/alex/.rvm/wrappers/ruby-1.9.3-p194/ruby;
      ...
  }

After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.

However I can't start it.

alex@ubuntu:~$ sh -x /etc/init.d/nginx start
sh: 0: Can't open /etc/init.d/nginx

sudo /etc/init.d/nginx start
sudo: /etc/init.d/nginx: command not found

The directory opt/nginx exists and there are files in it. Localhost:80 doesn't work either.

Any suggestions?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

The normal way to install nginx is via apt-get (or Synaptic or SW Center) and that doesn't put anything in /opt, AFAIK. In that case, you can stop/start it by simply issuing:

sudo service nginx start|stop|restart (etc)

If your nginx installed itself in /opt, I doubt it would have touched the /etc/init.d directory...

share|improve this answer
1  
It says 'nginx: unrecognized service' –  Alex Malex Jul 29 '12 at 8:59
1  
sudo apt-get install nginx –  izx Jul 29 '12 at 9:00
1  
Why? it previously said 'Nginx with Passenger support was successfully installed.' –  Alex Malex Jul 29 '12 at 9:02
2  
You are following a tutorial for Mac, which clearly says start nginx directly with sudo and stop with killall, and then you ask why it isn't installed as a service!? –  izx Jul 29 '12 at 9:08
2  
I believe OP is asking about nginx + passenger, not vanilla nginx. –  user10962 Jul 13 '13 at 17:27
add comment

The usual way of installing a Rails + NGINX + Passenger + RVM setup usually involves nginx being placed in /opt/nginx, but it in fact doesn't create the init.d startup file. This blog post shows how you can easily grab one from Linode:

wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

For posterity, here is the script from Linode:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
              --exec $DAEMON
          echo "$NAME."
          ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1
            ;;
    esac

    exit 0

One thing to look out for: if you've changed your nginx.pid location (defaults to /opt/nginx/log, I changed mine to /var/run), you'll need to change it in this file. Near the top, just declare it as a variable:

PIDPATH=/var/run/$NAME.pid

And replace anywhere that has the path to the pid with $PIDPATH. (Even if you're keeping the original path, this makes the script more readable).

share|improve this answer
add comment

I recommend using the Brightbox PPA mentioned in the Brightbox Wiki. This enables all normal service handing like service nginx start or /etc/init.d/nginx start out of the box.

This works fine for me in precise (12.04 LTS).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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