title: NginX and Rails : Subdomain doesn't not work
body: <p>It's been 2 days that I try to setup NginX to work with subdomain.</p>
  
  <p>Here is my ".conf" for NginX :</p>
  
  <pre><code>upstream mydomain_staging {
          server unix:tmp/unicorn.mydomain_staging.sock fail_timeout=0;
  }
  
  server {
          listen   80; ## listen for ipv4; this line is default and implied
          #listen   [::]:80 default ipv6only=on; ## listen for ipv6
  
          root /home/mtaville/mtaville_staging/current/public;
  
          # Make site accessible from http://localhost/
          server_name staging.mydomain.fr admin.staging.mydomain.fr;
  
          location ^~ /assets/ {
                  gzip_static on;
                  expires max;
                  add_header Cache-Control public;
          }
  
          location /doc/ {
                  alias /usr/share/doc/;
                  autoindex on;
                  allow 127.0.0.1;
                  deny all;
          }
  
          location / {
                  try_files $uri $uri/index.html $uri.html @mydomain_staging;
          }
  
          location @mydomain_staging {
                  proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
                  proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
                  proxy_redirect     off;
  
                  proxy_set_header   X-Forwarded-Proto $scheme;
                  proxy_set_header   Host              $http_host;
                  proxy_set_header   X-Real-IP         $remote_addr;
                  proxy_set_header   X-Forwarded-For   $remote_addr;
  
                  proxy_pass http://mydomain_staging;
          }
  
  }
  </code></pre>
  
  <p>When I try to access to staging.mydomain.fr, it works ! But when I try to access to admin.staging.mydomain.fr, the frontend is displaying instead of backend ;</p>
  
  <p>Here is my routes.rb :</p>
  
  <pre><code>MyApp::Application.routes.draw do
  
    constraints(subdomain: /admin/) do
      match '/', to: 'dashboard#show', as: :admin_root
      resources :posts, controller: "admin/posts"
    end
  
    root to: "pages#home"
  
  end
  </code></pre>
  
  <p>I do not know why it doesn't work ! Anybody help me ?</p>
  
  <p>Thanks a lot !</p>