I am unable to get the subdomain from the URL in NGINX

Posted by Jean-Nicolas Boulay Desjardins on Server Fault See other posts from Server Fault or by Jean-Nicolas Boulay Desjardins
Published on 2013-06-28T02:13:16Z Indexed on 2013/06/28 4:22 UTC
Read the original article Hit count: 449

Filed under:

I am unable to get the subdomain from the URL in NGINX.

Here is my config:

server {
    listen  80;
    server_name     ~^(?<appname>)\.example\.com$;

    rewrite ^ https://$appname.example.com$request_uri? permanent;
}

When I do:

http://bob.example.com/

I am sent to:

https://.example.com/

I don't know what I am doing wrong.

I am using NGiNX 1.2.7.

I have another config for the:

http://example.com/

So I have one server block for the domain without the subdomain and the second with the subdomain... This is about the subdomain.

© Server Fault or respective owner

Related posts about nginx