Skip to content

Instantly share code, notes, and snippets.

@vladvinnikov
Created February 27, 2013 09:03
Show Gist options
  • Save vladvinnikov/5046473 to your computer and use it in GitHub Desktop.
Save vladvinnikov/5046473 to your computer and use it in GitHub Desktop.
Попробуйте http://nginx.org/en/docs/http/ngx_http_upstream_module.html#least_conn
Ну или haproxy с "balance leastconn".
Конфиги типа таких
на сервере, где стоит nginx, который распределяет запросы
upstream myserv_production {
ip_hash;
server 127.0.0.1:1157 max_fails=5 fail_timeout=10s;
server 55.99.33.222:9091 max_fails=5 fail_timeout=10s;
}
server {
listen 80;
server_name
i0.myserv.ru
i1.myserv.ru
i2.myserv.ru
i3.myserv.ru
;
access_log off;
error_log /var/log/nginx/static.myserv.ru.error.log;
log_not_found off;
gzip on;
gzip_min_length 1000;
gzip_disable "msie6";
gzip_comp_level 4;
gzip_types text/plain application/xhtml+xml text/xml application/xml application/xml+rss
text/json application/json
text/javascript application/x-javascript text/css;
if ($request_method !~ ^(GET|POST|PUT|DELETE|HEAD)$ ) {
return 444;
}
root /var/www/myserv/current/public;
location ~* \.(ico|css|js|gif|jpg|jpeg|png|mp4|flv|f4v)(\?[0-9]+)?$ {
expires max;
break;
}
location / {
expires max;
try_files $uri @myserv_production;
rewrite ^ http://www.myserv.ru$request_uri? permanent; #301 redirect
}
location @myserv_production {
include proxy_params;
proxy_pass http://myserv_production;
}
}
location / {
rewrite ^/(.*)/$ /$1 permanent;
root /var/www/myserv/current/public;
rewrite ^/?page=8&tab=contest / permanent;
if (-f $document_root/system/maintenance.html) {
return 503;
}
try_files $uri $uri/index.html $uri.html @myserv_production;
}
location @myserv_production {
access_log /var/log/nginx/myserv.ru.access.log;
include proxy_params;
proxy_pass http://myserv_production;
}
И второй, сервер
server {
listen 80;
server_name
i0.myserv.ru
i1.myserv.ru
i2.myserv.ru
i3.myserv.ru
;
access_log off;
error_log /var/log/nginx/static.myserv.ru.error.log;
log_not_found off;
proxy_buffering off;
gzip on;
gzip_min_length 1000;
gzip_disable "msie6";
gzip_comp_level 4;
gzip_types text/plain application/xhtml+xml text/xml application/xml application/xml+rss
text/json application/json
text/javascript application/x-javascript text/css;
if ($request_method !~ ^(GET|POST|PUT|DELETE|HEAD)$ ) {
return 444;
}
location ~* \.(ico|gif|jpg|jpeg|png|mp4|flv|f4v)(\?[0-9]+)?$ {
add_header Cache-Control public;
root /media/storage00/backups/current/storage00/var-www/myserv/shared;
expires max;
try_files $uri @web_static;
break;
}
location / {
add_header Cache-Control public;
expires max;
root /media/storage00/backups/current/storage00/var-www/myserv/shared;
try_files $uri @web1_unicorn;
rewrite ^ http://www.myserv.ru$request_uri? permanent; #301 redirect
}
location @web1_unicorn {
include proxy_params;
proxy_pass http://127.0.0.1:9090;
}
location @web_static {
include proxy_params;
proxy_pass http://176.9.50.182;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment