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.
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.
Let's start up Nginx:
sudo /etc/init.d/nginx start
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:
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
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:
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
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.