Category:Nginx

nginx (pronounced “engine-x”) is an open source Web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. It is licensed under a BSD-like license and it runs on Unix, Linux, BSD, Mac OS X, Solaris, AIX and Microsoft Windows.

Nginx Configuration Options

 * expires - Controls whether the response should be marked with an expiry time, and if so, what time that is.
 * gzip - This module allows for on-the-fly gzip compression. See also Gzip pre-compression module.
 * gzip pre-compression - Before serving a file from disk to a gzip-enabled client, this module will look for a precompressed file in the same location that ends in ".gz".

A Very Simple Nginx Proxy Setup
In the below example, you need to set nginx-ip-here & ip-address-of-your-server. server { #Turns access log off access_log off; #Set this to the IP on the nginx server you want to represent this proxy listen nginx-ip-here:80; #Matches the requested hostname server_name your-hostname.com www.your-hostname.com; location / { # Tells the destination server the IP of the visitor (some take X-Real-IP,         # some take X-Forwarded-For as their header of choice         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-For $remote_addr;         # Tells the destination server which hostname you want         proxy_set_header Host $host;         # Performs a Proxy Pass to that server         proxy_pass http://ip-address-of-your-server;     } }

Multiple Server Configuration (with two domains)
upstream www.domain1.com  { server  192.168.10.11:80; server  192.168.10.12:80; } server { listen 80; server_name www.domain1.com; location / { proxy_pass        http://www.domain1.com; proxy_set_header  Host             $host; proxy_set_header  X-Real-IP        $remote_addr; proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for; } } upstream www.domain2.com  { server  192.168.10.21:80; server  192.168.10.22:80; } server { listen 80; server_name www.domain2.com; location / { proxy_pass        http://www.domain2.com; proxy_set_header  Host             $host; proxy_set_header  X-Real-IP        $remote_addr; proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for; }       access_log  /usr/local/nginx/logs/domain2.log  www; }

Changing Configuration
After updating the configuration of Nginx, you can send a HUP signal to the master process to have Nginx reload the configuration. nginx -s reload