Starting nginx on Ubuntu 12.04 with init.d and custom configuration file


I have an nginx configuration specific to a project I'm currently working on (Django, to be precise).

It looks like the "right" way to start nginx on Ubuntu is

sudo /etc/init.d/nginx start

However, I want to supply a custom configuration file. Normally I'd do this in the following way:

sudo nginx -c /my/project/config/nginx.conf

Looking at the init.d/nginx file, it doesn't look like there the start command passes in any arguments, so I can't do

sudo /etc/init.d/nginx start -c /my/project/config/nginx.conf

What's the best way to solve my problem?

By : mallyvai


init.d is not the right supervisor to use on Ubuntu anymore, you should use Upstart. Put this in /etc/init/nginx.conf and you will be able to start/stop it with sudo start nginx and sudo stop nginx:

description "nginx http daemon"
author "George Shammas"

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

env DAEMON=/usr/local/nginx/sbin/nginx -c /my/project/config/nginx.conf
env PID=/usr/local/nginx/logs/

expect fork
respawn limit 10 5

pre-start script
    $DAEMON -t
    if [ $? -ne 0 ]
            then exit $?
end script

exec $DAEMON

This video can help you solving your question :)
By: admin