NGINX 부하 균형 이 금 산 소요 망 에서 의 배치

9253 단어 nginx
user  www www;

worker_processes 8;

error_log  /data1/logs/nginx_error.log  crit;

pid        /usr/local/webserver/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process. 
worker_rlimit_nofile 51200;

events 
{
 use epoll;
 worker_connections 51200;
}

http 
{
 include       mime.types;
 default_type  application/octet-stream;

 #charset  utf-8;
     
 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
     
 sendfile on;
 #tcp_nopush     on;

 keepalive_timeout 30;

 tcp_nodelay on;

 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;

 gzip on;
 gzip_min_length  1k;
 gzip_buffers     4 16k;
 gzip_http_version 1.1;
 gzip_comp_level 2;
 gzip_types       text/plain application/x-javascript text/css application/xml;
 gzip_vary on;

 limit_zone  anti_attack  $binary_remote_addr  10m;

 #                  
 client_max_body_size     300m;

 #                                   
 client_body_buffer_size  128k;
              
 #             _            
 proxy_connect_timeout    600;
                
 #     _           _                 
 proxy_read_timeout       600;
              
 #           _                       
 proxy_send_timeout       600;
              
 #       _                 Nginx      _             
 proxy_buffer_size        16k;
              
 #     Nginx        Buffer        
 proxy_buffers            4 32k;
              
 #                proxy_buffers     *2 
 proxy_busy_buffers_size 64k;
              
 #proxy         
 proxy_temp_file_write_size 64k;

 #  
 proxy_temp_path /data2/proxy_temp_path;
 proxy_cache_path  /data2/proxy_cache_path  levels=1:2   keys_zone=cache_one:2000m inactive=1d max_size=5m;

 upstream my_server_pool {
   server   xx.xx.xx.1:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.2:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.3:80 weight=1 max_fails=2 fail_timeout=30s;
 }
 
 upstream php_server_pool {
   server   xx.xx.xx.4:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.5:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.6:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.7:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.8:80 weight=1 max_fails=2 fail_timeout=30s;
 }

 upstream bbs_server_pool {
   ip_hash;
   server   xx.xx.xx.9:80 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.10:80 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.11:80 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.12:80 max_fails=2 fail_timeout=30s;
 }

 upstream cms_server_pool {
   server   xx.xx.xx.13:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.14:80 weight=1 max_fails=2 fail_timeout=30s;
 }
 
 upstream pic_server_pool {
   server   xx.xx.xx.15:80 weight=1 max_fails=2 fail_timeout=30s;
   server   xx.xx.xx.16:80 weight=1 max_fails=2 fail_timeout=30s;
 }

 upstream xoyohimsg_server_pool {
   server   xx.xx.xx.17:3245;
   server   xx.xx.xx.18:3245 down;
 }

 #xoyo.com     www.xoyo.com
 server
 {
   listen       80;
   server_name  xoyo.com;

   rewrite ^/(.*) http://www.xoyo.com/ permanent;

   access_log  /data1/logs/xoyo.com_access.log;
 }

 #    HTTPS/SSL    
 server
 {
   listen       443;
   server_name  my.xoyo.com;

   ssl on;
   ssl_certificate my.xoyo.com.crt;
   ssl_certificate_key my.xoyo.com.key;

   location /
   {
         proxy_pass http://php_server_pool;
         proxy_set_header Host  my.xoyo.com;
         proxy_set_header X-Forwarded-For  $remote_addr;
   }

   access_log  /data1/logs/my.xoyo.com_access.log;
 }

 #     ,               
 server
 {
   listen       80;
   server_name  pic.xoyo.com;

   location /cms/
   {
         proxy_pass http://cms_server_pool;
         proxy_set_header Host  pic.xoyo.com;
                 proxy_set_header X-Forwarded-For  $remote_addr;
   }

   location /
   {
         proxy_pass http://pic_server_pool;
         proxy_set_header Host  pic.xoyo.com;
                 proxy_set_header X-Forwarded-For  $remote_addr;
   }

   access_log  /data1/logs/pic.xoyo.com_access.log;
 }

 #        ,       
 #limit_zone   media  $binary_remote_addr  10m;
 server
 {
   listen       80;
   server_name  media.xoyo.com;

   location /
   {
       proxy_pass http://cms_server_pool;
       proxy_set_header Host  $host;
       proxy_set_header X-Forwarded-For  $remote_addr;

      valid_referers none blocked www.xoyo.com *.xoyo.com www.kingsoft.com *.kingsoft.com www.kingsoft.cn *.kingsoft.cn;
      if ($invalid_referer) {
          rewrite ^/ http://www.xoyo.com;
      }
   }

   access_log  /data1/logs/media.xoyo.com_access.log;
 }

 #        ,      HTTP   
 server
 {
   listen       80;
   server_name  hi.xoyo.com;

   #                  HTTP   
   location /recmessage.xoyo
   {
         proxy_pass http://xoyohimsg_server_pool;
         proxy_set_header Host  $host;
   }

   location /
   {
         proxy_pass http://php_server_pool;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
   }

   access_log  /data1/logs/hi.xoyo.com_access.log;
 }

 #      ,    、Flash、JavaScript、CSS、  HTML  Web  
 server{
   listen 80;
   server_name  bbs.xoyo.com *.bbs.xoyo.com bbs.xoyo.kingsoft.com;

   location /
   {
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
         proxy_pass http://bbs_server_pool;
   }

   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html|shtml)$
   {
         proxy_cache cache_one;
         proxy_cache_valid  200 10m;
         proxy_cache_valid  304 1m;
         proxy_cache_valid  301 302 1h;
         proxy_cache_valid  any 1m;
         proxy_cache_key $host$uri$is_args$args;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
         proxy_pass http://bbs_server_pool;
   }
  

   log_format  bbs  '$remote_addr $host $remote_user [$time_local] "$request"'
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for'; 
   access_log /data1/logs/bbs.xoyo.com_access.log bbs;
 }


 #        ,       256KB/ 
 server{
   listen       80;
   server_name  att03.bbs.xoyo.com att02.bbs.xoyo.com att01.bbs.xoyo.com;

   location /
   {
         #       256kB/ 
         limit_rate  256k;
         proxy_pass http://xx.xx.xx.19;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
   }
  
   access_log off;
 }

 #    SNS  ,             ,    、Flash、JavaScript、CSS  Web   
 server{
   listen       80;
   server_name  hu.xoyo.com *.hu.xoyo.com;

   location /
   {
         proxy_pass http://php_server_pool;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
   }

   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
   {
         proxy_cache cache_one;
         proxy_cache_valid  200 10m;
         proxy_cache_valid  304 1m;
         proxy_cache_valid  301 302 1h;
         proxy_cache_valid  any 1m;
         proxy_cache_key $host$uri$is_args$args;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
         proxy_pass http://php_server_pool;
   }

   location ~ ^/admincp.php
   {
         #             
         proxy_pass http://xx.xx.xx.4;
         proxy_set_header Host  $host;
         proxy_set_header X-Forwarded-For  $remote_addr;
   }

   access_log /data1/logs/hu.xoyo.com_access.log;
 }
}

좋은 웹페이지 즐겨찾기