Gentoo - Installing Nginx
Nginx is a lightweight web server, popular with those who don't need the extra services that Apache offers and are looking for less bulky alternatives.
This article will look at installing Nginx on a Gentoo slice.
The Gentoo package manager usually offers very recent releases of Nginx, so we'll look at installing it with the 'emerge' command and won't worry about installing it from source.
The 'emerge' command still gives us a lot of flexibility and takes care of dependencies too.
Versions
At the time of writing, the latest stable release of Nginx is 0.7.62. This is the case for both the source package offered by Nginx's maintainers and the package available via 'emerge'. The Gentoo package was released within four days of the source code, on 18 September 2009.
Install and Dependencies
Installing Nginx is incredibly simple as it involves a single command:
sudo emerge nginx
This will install any and all dependencies that Nginx requires, such as libpcre.
Start
Let's start up Nginx:
sudo /etc/init.d/nginx start
Done.
Configuration
In my case, I found that with the default configuration, Nginx only listened on the slice's loopback interface (127.0.0.1).
This means we wouldn't be able to connect to the web server from outside the slice — very secure, but not very useful.
This can be changed in Nginx's main configuration file:
sudo nano /etc/nginx.conf
Change the listen line from:
listen 127.0.0.1;
to:
listen 0.0.0.0;
0.0.0.0 means it will listen on all interfaces, both public and private. Or we can use the slice's public IP.
Once we've saved the changes, we need to restart Nginx; a mere reload won't work for 'listen' changes:
sudo /etc/init.d/nginx restart
Start on boot
Now we'll configure Nginx to start automatically whenever the slice is rebooted:
sudo rc-update add nginx default
Navigate
Finally, let's test the installation. If we navigate to our slice's public IP using a web browser, we should be greeted with this wonderfully simple welcome screen:

Init scripts
The installation process created Nginx's init scripts and added them to the relevant run levels, placing these commands are at our disposal for controlling the web server:
sudo /etc/init.d/nginx start
...
sudo /etc/init.d/nginx stop
...
sudo /etc/init.d/nginx restart
That's it.
Summary
It's simple to install and run Nginx on a Gentoo slice.
Emerge handles the dependencies and sets up an init script framework for controlling the web server.
—
matiu


Article Comments:
Toskana commented Sun Mar 07 00:24:34 UTC 2010:
Nginx sees like a great solution for my server.Thanks for such a detailed post on that topic.Good written! Best regards, Helen.