HTTP map 模块

回复 收藏
本帖最后由 乐橙306 于 2016-3-13 11:20 编辑

参考文档
HTTP  map   模块
http://nginx.org/en/docs/http/ngx_http_map_module.html
  1. #map模块 :创建变量,其值依赖其他变量的值
  2. #语法: map string $variable { ... }  
  3. #用于获取client原始IP地址
  4.     map $http_x_forwarded_for $clientRealIp {
  5. #创建变量clientRealIp
  6.         "" $remote_addr;
  7. #调用remote_addr
  8.         ~^(?P[0-9\.]+),?.*[        DISCUZ_CODE_6        ]nbsp;  $firstAddr;
  9. #用正则匹配,从http_x_forwarded_for中取得用户的原始IP
  10.         }
  11. #针对client真实IP地址做限制
  12.     limit_conn_zone $clientRealIp zone=connRealIp:10m;
  13. #定义一个会话存储空间,key=$clientRealIp ,会话存储空间大小为10m
  14.     limit_req_zone  $clientRealIp zone=reqRealIp:10m rate=10r/s;
  15. #定义了一个zone,会话存储空间大小为10m,该区域的处理请求速度平均值不能超过每秒10个

2016-03-13 10:43 举报
已邀请:
0

乐橙306

赞同来自:

  1. 一个典型的使用映射的例子是代替一个含有很多服务器的/location或者重定向:
  2. map $uri $new {
  3.   default        http://www.domain.com/home/;

  4.   /aa            http://aa.domain.com/;
  5.   /bb            http://bb.domain.com/;
  6.   /john          http://my.domain.com/users/john/;
  7. }

  8. server {
  9.   server_name   www.domain.com;
  10.   rewrite  ^    $new   redirect;
  11. }
0

乐橙306

赞同来自:

  1. http {
  2. map $http_user_agent $agent {
  3. ~curl curl;
  4. ~*chrome chrome;
  5. }
  6. server {
  7.         listen       8080;
  8.         server_name  test.ttlsa.com;

  9.         location /hello {
  10. default_type text/plain;
  11. echo http_user_agent: $http_user_agent;
  12. echo agent: agent:$agent;
  13. }
  14. }
  15. }

回复帖子,请先登录注册

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