Sunday, August 11, 2013

How to Multiple domains load banlance with nginx

Source: http://www.goitworld.com/how-to-multiple-domains-load-banlance-with-nginx/
Nignx is a very great web server and load banlancer. In my “Nginx Server” category have more about nginx.
f you want to configure multiple mongrel clusters to be used with multiple domains or sub-domains then define multiple upstream blocks and server blocks and add it to the same nginx config file.

master config part:

worker_processes  20;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
      use epoll;
      worker_connections 51200;
}
http {
log_format  www  ‘$remote_addr – $remote_user [$time_local] $request ‘
                        ‘"$status" $body_bytes_sent "$http_referer" ‘
                        ‘"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"’;
access_log  logs/access.log  main;
client_header_timeout   10m;
client_body_timeout     10m;
send_timeout            10m;
client_max_body_size     4m;
client_body_buffer_size    256k;
connection_pool_size            256;
client_header_buffer_size       1k;
large_client_header_buffers     4 2k;
request_pool_size               4k;
output_buffers  1 32k;
postpone_output 1460;
tcp_nopush     on;
tcp_nodelay    on;
gzip  on;
gzip_comp_level  3;
gzip_min_length  1100;
gzip_buffers  4 8k;
gzip_proxied any;
gzip_http_version  1.1;
gzip_types  text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascri
pt;
include       mime.types;
default_type  application/octet-stream;
keepalive_timeout 120;

Multiple domains load banlancer config part:

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;
}

No comments:

Router Packet Networking

Đây là video ngắn khá hay, mô tả đường đi của một gói tin trên Mạng Internet.