Tags

, ,

Source: http://wiki.nginx.org/

http://nginx.net/

NGINX™ is advanced Internet infrastructure software. It is a high performance web server with the lowest memory footprint and it provides complete combination of the most essential features required to build modern and efficient web infrastructure.

Today NGINX is the 2nd most popular open source web server on the Internet.
NGINX functionality includes HTTP web server, HTTP and mail reverse proxy, content caching, load balancing, compression, bandwidth policing, connection multiplexing and reuse, SSL offload and media streaming.
You can install NGINX official Debian/Ubuntu packages. Append the appropriate stanza to /etc/apt/sources.list:
Ubuntu 10.04:
root@server:/# deb http://nginx.org/packages/ubuntu/ lucid nginx
root@server:/# deb-src http://nginx.org/packages/ubuntu/ lucid nginx
root@server:/# apt-get install nginx to install NGINX.
NGINX configuration file reside in /etc/nginx folder. Add following configuration to nginx.conf file.
user  nginx;
worker_processes  2;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
use epoll;
}
http {
    server_names_hash_bucket_size 64;
    include       /etc/nginx/mime.types;
    include     drop.lasso.conf;
    default_type  application/octet-stream;
    limit_req_zone  $binary_remote_addr  zone=one:10m   rate=1r/s;
    log_format main ‘$remote_addr – $remote_user [$time_local] ‘
                    ’”$request” $status $body_bytes_sent “$http_referer” ‘
                    ‘”$http_user_agent” “$http_x_forwarded_for”’;
    access_log  /var/log/nginx/access.log;
    # spool uploads to disk instead of clobbering downstream servers
    client_body_temp_path /var/spool/nginx-client-body 1 2;
    client_max_body_size 32m;
    client_body_buffer_size    128k;
   
    server_tokens       off;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         off;
    keepalive_timeout   5;
  
   ## Timeouts
    client_body_timeout   60;
    client_header_timeout 60;
    expires               24h;
    send_timeout          60;
   ## General Options
    ignore_invalid_headers   on;
    keepalive_requests      100;
    limit_zone gulag $binary_remote_addr 5m;
    recursive_error_pages    on;
    server_name_in_redirect off;
    ## Compression
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_min_length  1100;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/x-javascript
        text/xml application/xml application/xml+rss text/javascript;
    # Some version of IE 6 don’t handle compression well on some mime-types,
    # so just disable for them
    gzip_disable “MSIE [1-6].(?!.*SV1)”;
    # Set a vary header so downstream proxies don’t send cached gzipped
    # content to IE6
    gzip_vary on;
   
    # proxy settings
    proxy_redirect     off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;
    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
    include /etc/nginx/conf.d/*.conf;
}
Configuration:
root@server:/# cd /etc/nginx/conf.d/
root@server:/etc/nginx/conf.d# vi fakrul.com
[fakrul.com is your domain name]
server {
    listen       80;
    server_name www.fakrul.com;
    access_log  /var/log/nginx/fakrul.access.log;
    error_log   /var/log/nginx/fakrul.error.log;
     ## Only requests to our Host are allowed
      if ($host !~ ^(fakrul.com|www.fakrul.com)$ ) {
         return 444;
      }
     ## Only allow these request methods
      if ($request_method !~ ^(GET|HEAD|POST)$ ) {
         return 444;
      }
    # proxy to Apache 2 and mod_python
    location / {
        proxy_pass         http://192.168.100.100:80/; #your original web server running on 192.168.100.100.80
        proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_max_temp_file_size 0;
        client_max_body_size       10m;
        client_body_buffer_size    128k;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
    }
}
root@server:/etc/nginx/conf.d# /etc/init.d/nginx start
Check the web server log.
root@server:/etc/nginx/conf.d# tail -f /var/log/nginx/fakrul.access.log
You can get the details performance analysis of NGINX & Apache from