V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
georgetso
V2EX  ›  NGINX

2questions on nginx

  •  
  •   georgetso · 2013-07-02 16:06:12 +08:00 · 2212 次点击
    这是一个创建于 3951 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1.
    在 http {} 部分, 设置了
    map $http_header_1 $route {default 10;}
    map $http_header_2 $route {default 20;}
    map $http_header_3 $route {default 30;}

    请求的header设置为 curl -H "header_1:0" http://xxx.com/xxx
    然后在 server {} 部分, echo "$route"; 打印结果始终为 30, 因为 第三个map指令覆盖了前面的值;

    问题来了: 如何在map部分根据不同的header, 获得想要的值?

    2.
    为解决问题1, 我想的办法为
    map $http_header_1 $route1 {default 10;}
    map $http_header_2 $route2 {default 20;}
    map $http_header_3 $route3 {default 30;}

    然后在 location {} 部分, 用 if ($http_header_1) {echo "$route1";} 去获得想要的值;
    可耻的是, 这个 if 似乎没成功, 而且nginx不推荐使用if

    ------
    那么, 哪位深藏功与名的同学, 帮忙解答一下?
    1 条回复    1970-01-01 08:00:00 +08:00
    georgetso
        1
    georgetso  
    OP
       2013-07-02 16:30:06 +08:00
    好吧, 用if搞定了, 可是nginx不推荐使用if, 哪位同学有更好的方案?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2845 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:03 · PVG 15:03 · LAX 00:03 · JFK 03:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.