title: Rails 4 subdomains does not work on production
body: <p>I've created an Rails 4 application with 3 sub-domains.</p>
  
  <p>Development domains:</p>
  
  <ul>
  <li>mydomain.dev</li>
  <li>api.mydomain.dev</li>
  <li>account.mydomain.dev</li>
  </ul>
  
  <p>Production domains (Ngnix with Passenger):</p>
  
  <ul>
  <li>app.mydomain.com (www.mydomain.com and mydomain.com show other page, not the application)</li>
  <li>api.mydomain.com</li>
  <li>account.mydomain.com</li>
  </ul>
  
  <p>My config/routes.rb looks like that:</p>
  
  <pre><code>Rails.application.routes.draw do
      namespace :api, constraints: { subdomain: 'api' }, path: '/', defaults: { format: :json } do
          namespace :v1 do
              resources :clients, only: [:create, :show]
          end
      end
  
      namespace :account, constraints: { subdomain: 'account' }, path: '/' do
          get '/:locale' =&gt; 'welcome#index', locale: /en|pt/
          root 'welcome#index'
  
          scope "(:locale)", locale: /en|pt/ do
              get :sign_in, to: 'sessions#new'
              post :sign_in, to: 'sessions#create'
          end
      end
  
      get '/:locale' =&gt; 'welcome#index', locale: /en|pt/
      root 'welcome#index'
  
      scope "(:locale)", locale: /en|pt/ do
          resource :session, only: [:new, :create, :destroy]
          get :login, to: 'sessions#new', as: :login
      end
  end
  </code></pre>
  
  <p>My ngnix virtual host file:</p>
  
  <pre><code>server {
      listen 80;
      listen [::]:80;
  
      # SSL configuration
      #
      listen 443 ssl;
      listen [::]:443 ssl;
  
      server_name mydomain.com api.mydomain.com account.mydomain.com;
  
      passenger_enabled on;
      passenger_ruby /home/username/.rvm/gems/ruby-2.2.2@myapp/wrappers/ruby;
  
      root /var/sites/mydomain.com/current/public;
  
      ssl on;
      ssl_certificate /etc/nginx/ssl/mydomain.com/server.crt;
      ssl_certificate_key /etc/nginx/ssl/mydomain.com/server.key;
  }
  </code></pre>
  
  <p>The problem, is that on my dev machine (localhost) or development environment its works very well, as I want. But on production I got the error: "<code>The page you were looking for doesn't exist.</code>", with this log info: </p>
  
  <p>Visiting: <a href="https://account.mydomain.com/en/sign_in" rel="nofollow">https://account.mydomain.com/en/sign_in</a></p>
  
  <blockquote>
    <p>I, [2015-07-29T11:31:07.197635 #25813]  INFO -- : Started GET
    "/en/sign_in" for 0.0.0.0 at 2015-07-29 11:31:07 +0100 F,
    [2015-07-29T11:31:07.206758 #25813] FATAL -- :
    ActionController::RoutingError (No route matches [GET] "/en/sign_in"):
    actionpack (4.2.3)
    lib/action_dispatch/middleware/debug_exceptions.rb:21:in <code>call'<br>
    newrelic_rpm (3.12.1.298)
    lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in</code>call'
    actionpack (4.2.3)
    lib/action_dispatch/middleware/show_exceptions.rb:30:in <code>call'<br>
    newrelic_rpm (3.12.1.298)
    lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in</code>call'
    railties (4.2.3) lib/rails/rack/logger.rb:38:in <code>call_app'   railties
    (4.2.3) lib/rails/rack/logger.rb:20:in</code>block in call'</p>
  </blockquote>
  
  <p>in other works, account.mydomain.com and api.mydomain.com still acting as my main domain "mydomain.com" (as the same domain). </p>
  
  <p>UPDATE:</p>
  
  <p>I add this code on my page: </p>
  
  <pre><code>&lt;%= request.domain.inspect %&gt;&lt;br&gt;
  &lt;%= request.subdomain.inspect %&gt;
  </code></pre>
  
  <p>Visiting: <a href="http://api.mydomain.co.ao" rel="nofollow">http://api.mydomain.co.ao</a> 
  As Result I got:</p>
  
  <blockquote>
    <p>As Domain: "co.ao"</p>
    
    <p>As Subdomain: "api.mydomain"</p>
  </blockquote>
  
  <p>But my subdomain here is only: api </p>
  
  <p>What is wrong?</p>