Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:45:04+00:00 2026-06-11T05:45:04+00:00

I have a rails app which is deployed over Capistrano to a VPS with

  • 0

I have a rails app which is deployed over Capistrano to a VPS with a very similar setup to this Railscast. I have both mydomain.co.uk and admin.mydomain.co.uk. The subdomains work fine locally using lvh.me and the standard Webbrick server, but in production admin.mydomain.co.uk shows exactly the same content as mydomain.co.uk.

My routes.rb file:

class AdminDomain
  def self.matches?(request)
    puts "Sub = #{request.subdomain}"
    request.subdomain.present? && request.subdomain == "admin"
  end
end

MyApp::Application.routes.draw do

  constraints(AdminDomain) do
    scope :module => "admin" do
      match '', to: 'admin#index'

      resources :users
    end
  end

  # All the mydomain.co.uk routes...

My Nginx config:

upstream unicorn {
  server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}

server {
  listen 80;
  root <%= current_path %>/public;

  server_name mydomain.co.uk admin.mydomain.co.uk;

  listen 443 ssl;
  ssl_certificate /home/deployer/mydomain_combined.crt;
  ssl_certificate_key /home/deployer/mydomain.key;
  proxy_set_header X-Forwarded-Proto $scheme;

  auth_basic            "Restricted";
  auth_basic_user_file  htpasswd;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location = /favicon.ico {
    expires    max;
    add_header Cache-Control public;
  }

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }

  error_page 503 @maintenance;

  location @maintenance {
    rewrite  ^(.*)$  /system/maintenance.html last;
    break;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

The only idea I have is that Nginx is not passing on the request url to the unicorn. I had a similar issue with SSL but solved that by adding proxy_set_header X-Forwarded-Proto $scheme;. How can I get the subdomains to function correctly in a production environment under Nginx and Unicorn?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:45:05+00:00Added an answer on June 11, 2026 at 5:45 am

    It seems that under my setup in production request.subdomain was set to ‘admin.mydomain’ whereas in development it was just ‘admin’.

    Therefore adding this into the routes.rb with a regex works both locally and on my production server:

    constraints :subdomain => /admin.*/ do
      scope :module => "admin" do
        root to: 'admin#index'
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a Rails app (which in this case seems like it would
Is it feasible to have a Ruby on Rails app, which is: a) deployed
Hi I have a rails app which has a table called listings. This table
I have rails app which are working perfectly in the local computer. But when
I have a tab navigation page in my rails app which is shared across
I have my rails app, which is filled with products, set up with a
I have a Rails 3.1.3 app which uses devise for users authentication and soft-deletes
I have a rails app running on passenger standalone, which is working perfectly. I
I have got Sinatra/Rails app and an action which starts some long process. Ordinary
Simple rails app: I have 2 models, user and intro [which is simply a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.