【问题标题】:nginx rewrite rule for wildcard domain with same subdomain具有相同子域的通配符域的nginx重写规则
【发布时间】:2014-12-29 08:13:49
【问题描述】:

我很困惑,希望有人能提供帮助。我花了很长时间在网上寻找,但我迷失在语法上,我觉得我试图让事情变得过于复杂。

无论如何,我想做的是有一个 nginx 重写条件,将具有相同 images 子域的所有域指向具有自己子文件夹的通用 images 文件夹。

例子:

  • images.domain1.com 指向 /root/to/nginx/images/domain1.com/
  • images.domain2.com 指向 /root/to/nginx/images/domain2.com/

我发现了一篇文章,其中有人使用 server_name="~^(?<sub>.+)\.domain\.tld$" 之类的东西并将根指向 /root/to/nginx/domain.com/$sub - 但是当我尝试不同的组合以将正则表达式重新调整为 server_name="~images\.(?<domain>)$" 之类的东西并指向 /root/to/nginx/images/$domain 时,它没有重写成功。

非常感谢任何可以对此有所了解的人。

【问题讨论】:

  • 我对nginx不是很了解,但是你确定好的语法不是:server_name ~ "^(?<sub>.+)\.domain\.tld$"
  • 很遗憾没有 - 不过感谢您的回复。

标签: regex mod-rewrite nginx


【解决方案1】:

server_name 指令不采用等号。您的捕获组也是空的。

你应该改用server_name ~^images\.(?<domain>.+)$;

路径正确(/root/to/nginx/images/$domain)。

【讨论】:

  • @XavierLucas - 干杯,这真的很有帮助。不敢相信我的错误是多么愚蠢。非常感谢您的帮助:)
猜你喜欢
  • 2014-06-09
  • 1970-01-01
  • 2015-04-04
  • 2012-08-09
  • 2011-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
相关资源
最近更新 更多