Nginx on Gentoo RC Script

I build Nginx from source off of a fork/mirror so I can take advantage of a the fair proxy balancing policy. Buiding from source means crafting your own Gentoo rc script. Fortunately, the Nginx rc script distributed through Portage will work perfectly with a couple minor modifications.

You should only need to correct the path to the nginx executable, which should probably be /usr/local/sbin/nginx if you accepted the default build configurations:

$ sudo which nginx
/usr/local/sbin/nginx

Download and edit the rc script to use correct path to nginx:

$ cd ~
$ curl -0 http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/www-servers/nginx/files/nginx?rev=1.3 > nginx
$ vim nginx

Here are the changes that I made in the form of a patch:

17c17
<         --exec /usr/sbin/nginx -- -c /etc/nginx/nginx.conf
---
>         --exec /usr/local/sbin/nginx -- -c /etc/nginx/nginx.conf
38c38
<     /usr/sbin/nginx -c /etc/nginx/nginx.conf -t
---
>     /usr/local/sbin/nginx -c /etc/nginx/nginx.conf -t
40a41
> 

Finally, install the rc script and configure Nginx to start at boot:

$ sudo mv nginx /etc/init.d/
$ sudo chmod +x /etc/init.d/nginx
$ sudo rc-config add nginx default
$ sudo /etc/init.d/nginx start
$ rc-config show

Here’s the fork with the fair proxy balancing patch (download snapshot).

Sorry, comments are closed for this article.