nginx vhost配置文件+ua+status

# vhost配置文件

[root@LB01 ~]# cat /usr/local/nginx/conf/extra/b2b.conf
upstream b2b_server {
        #ip_hash;
        server 172.16.1.10:8201 weight=3 max_fails=3 fail_timeout=30;
        #server 172.16.1.110:8101 weight=1 max_fails=3 fail_timeout=30;
        #server 172.16.1.11:80 backup;
        }    

        server {
            listen 80;
            #charset utf-8;
            #charset GB2312;
            server_name www.pinhui001.com b2b.pinhui001.com pinhui001.com;
           
                #301跳转
                if ($host = 'pinhui001.com')
                {
                rewrite ^/(.*)$ http://www.pinhui001.com/$1 permanent;
                }
                # 移动端识别
                include extra/mobile.conf;
                #限制UA进行访问
                if ($http_user_agent ~ "Mozilla/4.0\ \(compatible;\ MSIE\ 9.0;\ Windows\ NT\ 6.1\)") {
                        return 555;
                }
                #限制UA进行访问
                if ($http_user_agent ~ "Mozilla/5.0\ \(Windows\ NT\ 6.3;\ Win64;\ x64\)\ AppleWebKit/537.36\ \(KHTML,\ like\ Gecko\)\ Chrome/39.0.2171.99\ Safari/537.36") {
                        return 444;
                }
                ##禁止访问指定目录
                #location /ashx/ {
                #每个IP并发连接数5
                limit_conn addr 20;
                #zone漏桶的名字,burst峰值,超过rate后可以容纳多少队列,nodelay是否延迟处理请求,或超过rate返回503
                limit_req zone=one burst=20 nodelay;
        
                #deny all;
                #}
        ###########pass b2b###############################################    
        location / {
                #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;
                proxy_pass http://b2b_server;
                #proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
               }
        #状态页面
        location /status {
                stub_status on;
                access_log off;
                auth_basic "Nginx Status";
                auth_basic_user_file /usr/local/nginx/conf/pinhui001.htpasswd;
                }
        ###################log format################################################
              access_log  logs/b2b_access.log access;
        }

 

posted @ 2017-05-04 20:21  sunmmi  阅读(370)  评论(0)    收藏  举报