Nginx

nginx is a robust, small and high performance web server and reverse proxy server. It is a good alternative to the popular available web servers like Apache and lighttpd.

Installation
Before immediately installing the package, first take a good look at the USE flags for Nginx.

Nginx uses modules to enhance its features. To simplify the maintenance of this modular approach, the nginx ebuild uses expanded USE flags to denote which modules should be installed. HTTP related modules can be enabled through the  variable whereas mail related modules can be enabled through the   variable.

These variables need to be set in. Their description can be found in /usr/portage/profiles/desc/nginx_modules_http.desc and /usr/portage/profiles/desc/nginx_modules_mail.desc.

Other USE flags are:

With the USE flags set, install :

Do not forget to add nginx to the default runlevel:

Configuration
The nginx configuration is handled by. Example 1 shows a single-site access, without dynamic capabilities (such as PHP).

Start nginx:

Verify nginx is running and responding as configured above:

Enabling PHP support
Add following lines to your nginx configuriation to enable PHP support. In this example nginx is exchanging information with the PHP process via a UNIX socket.

Additionally it is needed to build PHP with FastCGI Process Manager (php-fpm) support enabled. Add the fpm USE flag to the package:

Rebuild php with the new USE flag enabled.

Review the configuration, add following line:

Start the php-fpm daemon:

Add php-fpm to the default runlevel

Reload nginx with changed configuration

IP access list
Example 4 shows how to allow access to a particular site /nginx_status only to IP addresses are in CIDR notation, see definition example below:
 * certain hosts f.e. 192.0.2.1 127.0.0.1
 * and IP networks 198.51.100.0/24

Troubleshooting
Get general information using following troubleshooting commands.

Verify the running nginx configuration has no errors, nginx will only test -t the configuration without starting the process:

Check if the nginx process is running:

Verify nginx daemon is listening on TCP port 80:

External resources

 * nginx Wiki