【问题标题】:Nginx regular expression server_nameNginx 正则表达式 server_name
【发布时间】:2016-04-28 01:49:38
【问题描述】:

如何使用正则表达式来做到这一点:

preprod.*.company.com > root to /home/preprod_folder
*.company.com > root to /home/prod_folder

我知道要匹配 *.company.com 我将创建:

server_name *.company.com

但是对于 *.company.com 之前匹配的正则表达式,这条规则 preprod.allsubdomains.company.com

preprod.*.company.com 不工作,这很正常。

你能帮帮我吗?

谢谢。

【问题讨论】:

    标签: regex nginx server-name nginx-location


    【解决方案1】:

    您说“重定向”,但看起来您的意图是设置 root 目录。也许这就是您要寻找的:

        server_name ~^preprod\.(?<subdomain>\w+).company.com;
        root /home/prepod_folder;
    

    【讨论】:

    • 是的,这是可行的,但如果我添加另一个规则 *.company.com(所以两个规则),*.company.com 在你的规则之前匹配..
    • 我也为 *.company.com ( server_name ~^(?!preprod)\.(?\w+).mycompany.com; )) 添加了这条规则,这是有效的,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 2016-10-21
    • 2013-03-12
    • 2018-07-18
    • 2017-05-05
    • 2021-03-15
    相关资源
    最近更新 更多