Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have 3 subdomains: a.mydomain.com, b.mydomain.com, c.mydomain.com configured by domain provider as following:

Name TTL Type  Value
a    1d  CNAME @
b    1d  CNAME @
c    1d  CNAME @

And the nginx configuration of the service, that should be on the subdomain a:

server {
  listen 80;
  server_name a.mydomain.com;
  server_tokens off;
  root /nowhere;
  ...
  rewrite ^ https://a.mydomain.com$request_uri permanent;
}

server {
  listen 443;
  server_name a.mydomain.com;
  server_tokens off;
  ...
  # ssl staff and normal config
}

So the http://a.mydomain.com is forwarded to https://a.mydomain.com. Other subdomains are not configured. But somehow https://b.mydomain.com and https://c.mydomain.com are redirected to https://a.mydomain.com and http://a.mydomain.com, https://b.mydomain.com are not redirected.

Why it looks like there are no server_name setting in nginx config? I would like to have many subdomains on my nginx server

share|improve this question
    
Based on the configuration its because a.mydomain.com is the default rule. To avoid the behavior you experienced define the rule for the other domains. –  Ramhound Jun 24 '13 at 15:11
    
so the default rule - do the same redirect for all subdomains? But I did explicitly only server { ... server_name a.mydomain.com; } –  static Jun 24 '13 at 15:13
    
Have you tried to create a rule for those other domains. Your statement is also confusing, might want to read it again, and clarify the statement. –  Ramhound Jun 24 '13 at 15:23
    
@static When nginx receives a request for a domain for which it has no configuration (such as b.mydomain.com), it uses the configuration for the first server block it finds: In this case "rewrite the domain to https://a.mydomain.com"; The end result is http://b.mydomain.com is rewritten to https://a.mydomain.com. Write up configuration for b.mydomain.com before asking about why it isn't working. –  Darth Android Jun 24 '13 at 15:40
    
But the mydomain.com is not in the config and it opens the default nginx welcome-page. Why the b.mydomain.com cannot do the same (show the default nginx page)? –  static Jun 25 '13 at 13:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.