好吧。本来想多写点的,现在没时间,太监了。
说下核心:客户端自定义的http header,在nginx的配置文件里能直接读取到。
条件:header必须用减号“-”分隔单词,nginx里面会转换为对应的下划线“_”连接的小写单词。
nginx配置:
1 2 3 4 5 |
location / { if ($http_my_custom_header ~ (\d+) ) { rewrite / http://google.com/ last; } } |
测试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
wget --header="my-custom-header:1" -d https://blog.bbdd.ltd DEBUG output created by Wget 1.13.4 on linux-gnu. URI encoding = `UTF-8' --2014-04-28 09:48:40-- https://blog.bbdd.ltd/ Resolving bianbian.org (bianbian.org)... 172.31.30.70 Caching bianbian.org => 172.31.30.70 Connecting to bianbian.org (bianbian.org)|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: bianbian.org 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://google.com |