Nginx

From LinuxReviews
Jump to navigationJump to search

Nginx is a very light and efficient web server and reverse proxy. It is great for offloading images and other static files from heavy web servers such as apache.

CentOS[edit]

groupadd nginx

useradd -g nginx -d /dev/null -s /sbin/nologin nginx

mkdir src cd src wget http://nginx.org/download/nginx-1.1.3.tar.gz tar xfvz nginx-1.1.3.tar.gz cd nginx-1.1.3

./configure --with-ipv6 \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gzip_static_module \ --with-http_degradation_module make

su -c 'make install'

Add this to /usr/local/nginx/conf/mime.types:

File: /usr/local/nginx/conf/mime.types
[...]
    video/ogg                             ogm;
    video/ogg                             ogv;
    application/x-bittorrent              torrent;

Example configuration file:

File: /etc/nginx.conf
user nginx nginx;
worker_processes  4;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       /usr/local/nginx/conf/mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    gzip             on;
    gzip_static on;
    gzip_min_length  1000;
    gzip_comp_level   9;
    gzip_http_version 1.0;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain text/css application/x-javascript;
    gzip_disable     "MSIE [1-6]\.";
    gzip_vary         on;

    server {
        listen       85.25.250.68:80;
        server_name  static.everdot.org;
        root          /home/httpd/vhosts/static.everdot.org/httpdocs;
        charset utf-8;
        access_log  /var/log/nginx.log  main;
        location / {
            index  index.html index.htm;
        }
        location ~* \.(gif|jpg|png|css|js)$ {
                expires   30d;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

IPv6[edit]

IPv6 addresses must be put in [], for example:

File: /etc/nginx.conf
listen [::]:80;

To listen on a single IP:

File: /etc/nginx.conf
listen [2607:f0d0:1004:2::2]:80;
Web server software