I\'m very new to nginx, so forgive me if my explanations are off. I\'ll do my best to explain what I am trying to achieve.
Using WordPress and nginx, I would like us
the following should do it:
server {
listen 80; listen 443;
server_name *.example.com;
if ($host ~ "^(.*)\.example\.com$" ) { set $subdomain $1;}
rewrite ^ $scheme://example.com/$subdomain/$request_uri permanent;
}
(as an aside: the regex ^
matches all url's the most efficiently, and the standard nginx variable $request_uri
holds the uri including arguments so you don't need the (.*)
group in the rewrite)
additionally add a second serverblock for the domains you don't want redirected:
server {
listen 80; listen 443;
server_name cdn.example.com admin.example.com;
# do whatever with the requests of the reserved subdomains;
}