http://www.111cn.net/sys/nginx/68133.htm
好吧。本来想多写点的,现在没时间,太监了。
说下核心:客户端自定义的http header,在nginx的配置文件里能直接读取到。
条件:header必须用减号“-”分隔单词,nginx里面会转换为对应的下划线“_”连接的小写单词。
nginx配置:
代码如下 | 复制代码 |
location / { if ($http_my_custom_header ~ (d+) ) { rewrite / http://www.111cn.net/ last; } } |
测试:
代码如下 | 复制代码 |
wget --header="my-custom-header:1" -d http://www.111cn.net DEBUG output created by Wget 1.13.4 on linux-gnu. URI encoding = `UTF-8' --2014-04-28 09:48:40-- http://www.111cn.net/ Resolving www.111cn.net (www.111cn.net)... 172.31.30.70 Caching www.111cn.net => 172.31.30.70 Connecting to www.111cn.net |172.31.30.70|:80... connected. Created socket 3. Releasing 0x084e3e18 (new refcount 1). ---request begin--- GET / HTTP/1.1 User-Agent: Wget/1.13.4 (linux-gnu) Accept: */* Host: www.111cn.net Connection: Keep-Alive my-custom-header: 1 ---request end--- HTTP request sent, awaiting response... ---response begin--- HTTP/1.1 302 Moved Temporarily Server: nginx/1.1.19 Date: Mon, 28 Apr 2014 09:48:40 GMT Content-Type: text/html Content-Length: 161 Connection: keep-alive Location: http://www.111cn.net |