1

This is about an sample Rails app that uses subdomains. You can access it here: http://rodrigora.com.br. In this app, you can create site and specify one subdomain for it.

Example:

site: Google

subdomain: gog

This site should be accessible by http://gog.rodrigora.com.br

But, the app is unreacheable for any subdomain, neither www.


DNS server configuration:

DNS

nginx server configuration:

upstream app_server {
  server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}

server {
  listen 80 default;
  #server_name localhost;
  client_max_body_size 4G;
  keepalive_timeout 10;
  root /home/ubuntu/apps/blog/current/public;
  try_files $uri/index.html $uri.html $uri @app;

  location @app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app_server;
  }

  # Rails error pages
  error_page 500 502 503 504 /500.html;
  location = /500.html {
    root /home/ubuntu/apps/blog/current/public;
  }

  location ~ ^/(assets)/  {
    root /home/ubuntu/apps/blog/current/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }
}

Extra information: If I access www.rodrigora.com.br on browser, Google Chrome show the not found page,but nginx logs this line:

186.210.71.46 - - [21/Sep/2013:22:08:37 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"

Questions:

  • So, nginx is saying that the www subdomain is not there?

  • How to configure this app to respond to any subdomain?


Resources:

Railscast Subdomains

DNS propagation

Wildcard DNS check

1

2 Answers 2

3

Put the server name as *.rodrigora.com.br this will let the nginx server to accept any request with one of this domain subs.

-1

Have you tried listen 80 default_server;?

This might be more what you need. I believe that for server name _; is a catch-all.

server {
    listen 80 default_server;
    server_name _;
    rewrite ^(.*)$ http://www.domain.tld$1 permanent;
}
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .