【问题标题】:how to I match a url with post's variables如何将 url 与 post 变量匹配
【发布时间】:2012-05-31 09:00:23
【问题描述】:

如何将以下网址与 PCRE 匹配:

  1. http://www.test.com/abc?v=123&feature=True
  2. http://www.test.com/def?v=456&feature=True

我要做的是匹配域下的路径(abc或def), 这样我就可以使用 nginx 将请求重定向到指定的主机。

        #content of /etc/nginx/sites-enabled/default
             location / {
               #default redirect
                proxy_pass http://www.google.com;

               #redirect by domain name.
               if ($path ~* abc)
               {
                       proxy_pass http://10.1.1.47:8081?v=123&feature=True;
               }
               if ($path ~* edf)
               {
                       proxy_pass http://10.1.1.48:8081?v=456&feature=True;
               }
             }

PS:域名和路径不限于 www.test.com 和 (abc|def),分别。

谢谢!

【问题讨论】:

  • 到目前为止你有什么?

标签: regex nginx pcre


【解决方案1】:
location / {
    proxy_pass http://www.google.com;
}

location /abc/ {
    proxy_pass http://10.1.1.47:8081?v=123&feature=True;
}

location /edf/ {
    proxy_pass http://10.1.1.48:8081?v=456&feature=True;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多