关于nginx反向代理和负载均衡的架构

回复 收藏
user  www www;

worker_processes 8;

#error_log  /usr/local/nginx/logs/nginx_error.log debug;

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

worker_rlimit_nofile 65535;

events {
        use epoll;
        worker_connections 65535;
        }

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

  server_names_hash_bucket_size 256;
  client_header_buffer_size 64k;
  large_client_header_buffers 4 64k;
  client_max_body_size 8m;

  sendfile on;
  tcp_nopush     on;

  #
  client_body_buffer_size  700k;
  proxy_connect_timeout    120;
  keepalive_timeout 60; #60
  server_tokens off;

  tcp_nodelay on;
  #
  gzip  on;
  gzip_min_length  1k;
  gzip_buffers     4 8k;
  gzip_vary on;
  gzip_disable "MSIE [1-6]\.";
  gzip_comp_level 2;
  gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript;
  access_log off;
  proxy_temp_path   /data/nginx_cache/proxy_temp_dir;
  proxy_cache_path  /data/nginx_cache/proxy_cache_dir  levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=20g;
  #
#####################################################
  upstream http_backend_ssl {
  server xxx.xxx.xxx.xxx:443 weight=8 fail_timeout=3s backup;
  server xxx.xxx.xxx.xxx:444 weight=10 fail_timeout=8s;
  keepalive 16;
  }
#####################################
  upstream cspider_backend_ssl {
    server xxx.xxx.xxx.xxx:443;
  }
######################################
#first
server
{
listen 88;
index index.html;
root /usr/local/nginx/html;
}

####################################
# second
server {
    listen 1688;
    #proxy_buffering    off;
    #proxy_cache        off;
    proxy_set_header Accept-Encoding "";
##############################################
        if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") {
                return 444;
        }   #这里屏蔽蜘蛛吗
#####################################################
    #cache static files
    location ~ ^/(?!hmzs)(?!tonggao).*\.(gif|jpg|jpeg|png|bmp|swf)$   #这里(?!hmzs)(?!tonggao) 规则没看懂
    {
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
        proxy_cache cache_one;
        proxy_cache_valid  200 304 24h;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header           X-Real-IP $remote_addr;
        #  proxy_set_header           X_FORWARDED_PROTO https;
        proxy_set_header           X-Forwarded-For $remote_addr;
        #proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header           Host $host;
        proxy_pass https://http_backend_ssl;
        expires      1d;
    }
########################################################################
    location ~ ^/(?!hmzs)(?!tonggao).*\.js$
    {
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
        proxy_cache cache_one;
        proxy_cache_valid  200 304 24h;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header           X-Real-IP $remote_addr;
        #  proxy_set_header           X_FORWARDED_PROTO https;
        proxy_set_header           X-Forwarded-For $remote_addr;
        #proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header           Host $host;
        proxy_pass https://http_backend_ssl;
        expires      2h;
    }
    #
##############################################################################
    location /  {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass https://http_backend_ssl;
        proxy_http_version 1.1;
        proxy_set_header  Accept-Encoding  "";
        proxy_set_header Connection "";
        }
######################################################################################
    if ( $host ~* www\.jwshow\.net$ )  #这里也没看明白
        {
        rewrite /$ http://photo.163.com/jwjw.lucas@gmail.com/#m=0&p=1 redirect;
        }
#########################################################################################
    if ( $host ~* jwshow\.net$ )
        {
        rewrite /$ http://photo.163.com/jwjw.lucas@gmail.com/#m=0&p=1 redirect;
        }
#########################################################################################
    location /hmzs/ {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X_FORWARDED_PROTO https;
        proxy_pass https://cspider_backend_ssl;
        proxy_http_version 1.1;
        proxy_set_header  Accept-Encoding  "";
        }
###################
     access_log off;
#############
    }
######################################################################################################################3
#thrid
server {
    listen 443 ssl;
    #proxy_buffering    off;
    #proxy_cache        off;
    proxy_set_header Accept-Encoding "";
    ssl_certificate /usr/local/nginx/conf/jw129.com.crt;
    ssl_certificate_key /usr/local/nginx/conf/jw129.com.key;
    ssl_verify_client off;
##########################################################################################
    if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") {  
                return 444;  
        }
#########################################################################################
    #cache static files
    location ~ ^/(?!hmzs)(?!tonggao).*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
        proxy_cache cache_one;
        proxy_cache_valid  200 304 24h;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header           X-Real-IP $remote_addr;
        #  proxy_set_header           X_FORWARDED_PROTO https;
        proxy_set_header           X-Forwarded-For $remote_addr;
        #proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header           Host $host;
        proxy_pass https://http_backend_ssl;
        expires      1d;
    }
####################################################################################
    location ~ ^/(?!hmzs)(?!tonggao).*\.(js|css)$  #这里也没看明白
    {
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
        proxy_cache cache_one;
        proxy_cache_valid  200 304 24h;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header           X-Real-IP $remote_addr;
        #  proxy_set_header           X_FORWARDED_PROTO https;
        proxy_set_header           X-Forwarded-For $remote_addr;
        #proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header           Host $host;
        proxy_pass https://http_backend_ssl;
        expires      2h;
    }
    #
#####################################################################################
    location /  {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X_FORWARDED_PROTO https;
        proxy_pass https://http_backend_ssl;
        proxy_http_version 1.1;
        proxy_set_header  Accept-Encoding  "";
        }
########################################################################################
    location /hmzs/ {      #这里的/hmzs 指的什么目录 还是后端
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X_FORWARDED_PROTO https;
        proxy_pass https://cspider_backend_ssl;
        proxy_http_version 1.1;
        proxy_set_header  Accept-Encoding  "";
        }
####################################################################################
    }
###############################################################
}


2016-07-20 14:22 举报
已邀请:
0

乐橙306

赞同来自:

请直接把  你有疑问的地方 截取出来    列个123  

附 正则表达式规则  
麻烦 看完再问
http://www.apelearn.com/bbs/thread-11418-1-1.html
0

maria

赞同来自:

乐橙306 发表于 2016-7-20 15:13
请直接把  你有疑问的地方 截取出来    列个123  

附 正则表达式规则  

{:4_93:}你讲话总是这么犀利

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: