I've created an Rails 4 application with 3 sub-domains.
Development domains:
Production domains (Ngnix with Passenger):
My config/routes.rb looks like that:
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' => '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' => '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
My ngnix virtual host file:
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;
}
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: "The page you were looking for doesn't exist.
", with this log info:
Visiting: https://account.mydomain.com/en/sign_in
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
call'
call' actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in
newrelic_rpm (3.12.1.298) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:incall'
call' railties (4.2.3) lib/rails/rack/logger.rb:38:in
newrelic_rpm (3.12.1.298) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:incall_app' railties (4.2.3) lib/rails/rack/logger.rb:20:in
block in call'
in other works, account.mydomain.com and api.mydomain.com still acting as my main domain "mydomain.com" (as the same domain).
UPDATE:
I add this code on my page:
<%= request.domain.inspect %><br>
<%= request.subdomain.inspect %>
Visiting: http://api.mydomain.co.ao As Result I got:
As Domain: "co.ao"
As Subdomain: "api.mydomain"
But my subdomain here is only: api
What is wrong?
Default
tld_length = 1
You need to update tld_length to 2 for domain like: co.in, co.au
Try:
config.action_dispatch.tld_length = 2
in config/enviroments/production.rb
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With