Высокопроизводительный многофункциональный веб-сервер

http://nginx.org



 ./configure --with-http_realip_module
make install

/usr/local/nginx/sbin/nginx     собственно сервер
/usr/local/nginx/conf           конфигурационный каталог
/usr/local/nginx/logs           логфайлы
/usr/local/nginx/proxy_temp     кэш для proxy и вебакселератора

имеет смысл перелинковать часть директорий в привычные места

ln -s /usr/local/nginx/conf            /etc/nginx

rmdir /usr/local/nginx/logs ; mkdir /var/log/nginx ;
ln -s /var/log/nginx                   /usr/local/nginx/logs

rmdir /usr/local/nginx/proxy_temp ; mkdir -p /var/log/nginx/proxy_temp
ln -s /var/log/nginx/proxy_temp        /usr/local/nginx/proxy_temp

Либо прочтя ./configure --help сразу сконфигурить как надо
./configure --conf-path=/etc/nginx               \
        --http-log-path=/var/log/nginx           \
 --http-proxy-temp-path=/var/log/nginx/proxy_temp



nginx -t # тестирование конфигов

kill -HUP `cat nginx.pid` # перечитывание конфига

nginx -s [stop|quit|reload|reopen]

# глобальные конфиг-параметры можно подставлять в командной строке
nginx -g "pid /var/run/nginx.pid; worker_processes `sysctl -n hw.ncpu`;"




http://nginx.org/ru/docs/http/ngx_http_gzip_module.html
################## gzip    контекст: http #######################
  gzip            on;
  gzip_min_length 1000;
  gzip_proxied    expired no-cache no-store private auth no_last_modified;
  gzip_types      text/plain application/xml;
# gzip_http_version 1.1;
################## gziping #######################




http://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_buffering
  proxy_pass                 http://181.176.66.171: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;
  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 10m;
  proxy_max_temp_file_size   0;



   server {
        listen       181.176.66.164:80;
        server_name  suong.su www.suong.su;

        location / {
            proxy_pass   http://127.0.0.164;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
   #  proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

        }

        # Static files location
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|avi|mpeg|mpg|mov)$ {
            root   /home/www/$server_name;
        }
    }

# На проксируемом apache вписать в конфиг RPAF,
# чтоб вместо nginx'овского подставлялся IP web-клиента

RPAFenable On
RPAFproxy_ips 127.0.0.1 181.176.66.171
RPAFsethostname On
RPAFheader X-Real-IP

Если на фронте стоит nginx, то аналогичная настройка
на принимающем nginxe требует включения модуля http_realip_module
http://nginx.org/ru/docs/http/ngx_http_realip_module.html

 ./configure --with-http_realip_module

   set_real_ip_from 194.63.140.119;
   real_ip_header X-Forwarded-For;
   real_ip_recursive on;




Ограничение числа одновременных коннектов с одного IP
http://nginx.org/ru/docs/http/ngx_http_limit_conn_module.html

limit_conn_zone $binary_remote_addr zone=peripaddr:10m;
limit_conn_zone $server_name        zone=perserver:10m;

# для nginx 0.7 используется старый формат этой директивы
limit_zone peripaddr $binary_remote_addr 10m;

server {
    ...
    limit_conn perserver 100;
    ...
  location  /download/ {
    limit_conn peripaddr 10;
    }
  location  ~ \.rar$ {
    limit_conn peripaddr 1;
    }
}


Ограничение темпа запросов с одного IP
http://nginx.org/ru/docs/http/ngx_http_limit_req_module.html

Ограничение скорости на один IP
http://nginx.org/ru/docs/http/ngx_http_core_module.html#limit_rate

server {
    if ($slow) {         set $limit_rate 4k;     }


  location /flv/ {
    flv;
    limit_rate_after 500k;
    limit_rate       50k;
  }
}

Условия на активацию директив
http://nginx.org/ru/docs/http/ngx_http_rewrite_module.html#if
http://nginx.org/ru/docs/http/ngx_http_core_module.html#variables

$time_local
$time_iso8601

if ($slow) {
    limit_rate 10k;
}




DeflateEnable on
DeflateDisableRange "MSIE 4."
DeflateProxied on
# DeflateHTTP 1.0



Last-modified: Fri, 30 Jan 2015 15:01:32 GMT