Nginx variable for subdomain?

前端 未结 1 854
渐次进展
渐次进展 2021-02-07 22:03

I need a Guru\'s advice.

On Nginx\'s conf file, I would like to get the subdomain as a variable in order to redirect accesses as follow.

  • ACCES
相关标签:
1条回答
  • 2021-02-07 22:38

    You can use a regular expression in the server_name to extract the part you need as a named capture. For example:

    server {
        listen       80;
        server_name  ~^(?<name>.+)\.example\.com$;
        return       301 http://example.com/$name$request_uri;
    }
    

    See this document for more.

    0 讨论(0)
提交回复
热议问题