Nginx的负载均衡,如何让某段时间访问A机器

来源:互联网 发布:淘宝视频可以放几分钟 编辑:程序博客网 时间:2024/05/16 08:37

首先Nginx获取到时间

选取ngx_time_var模块
安装:

./configure –add-module=/path/to/ngx_http_time_var_module

示例:
echo 'year  :$tm_year'; //year  :2012echo 'month :$tm_month'; //month :01echo 'day   :$tm_day';  //day   :08echo 'hour  :$tm_hour';  //hour  :03echo 'minute:$tm_minute';  //minute:54echo 'second:$tm_second';  //second:21echo ''; echo $tm_err_log_time;  //2012/01/08 03:54:21echo $tm_http_time;  //Sat, 07 Jan 2012 19:54:21 GMTecho $tm_http_log_time;  //08/Jan/2012:03:54:21 +0800echo $tm_http_log_iso8601;  //2012-01-08T03:54:21+08:00echo ''; echo $tm_tomsec;  //1325966061.521echo $tm_tosec;  1325966061

配置Nginx

server {    server_name www.demo.com;    listen 80;    location / {        # 配置默认ip        set $default_ip 127.0.0.1;        # 配置默认port        set $default_port 8080;        # 如果当前时间是3-5点则指定ip为10.1.1.1        if ($tm_month>=3 && $tm_month <= 5) {            set $default_ip 10.1.1.1        }        # 如果url中包含ip=x        if ($request_uri ~* ip=(.+?)(&|$)) {            set $default_ip $1;        }        # 如果url中包含port=1        if ($request_uri ~* port=(\d+?)(&|$)) {            set $default_port $1;        }        # 配置代理参数        proxy_set_header Connection "";        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header Host $http_host;        proxy_set_header X-NginX-Proxy true;        # 代理        proxy_pass http://$default_ip:$default_port;    }}
原创粉丝点击