I have a domain, let's say example.com and I want to create a subdomain like page.example.com.

I've added a route in my rails routes.rb file:

class MySubDomain def self.matches?(request) request.subdomain.present? && request.subdomain == ("page" || "page.example.com") end end MyApp::Application.routes.draw do constraints(MySubDomain) do get '/' => 'static_pages#some_page' end root to: 'something#else'

When I browse to page.example.com in development (using pow) then it lands on the appropriate controller. For production I've created a DNS entry like:

A record for page.example.com pointing to IP of the VPS.

When I hit page.example.com in the browser then it just sends me to example.com.

When I curl page.example.com then the response is the one I expect.

My nginx config is as follows:

upstream example.com {server unix:/tmp/benchmark_app.sock fail_timeout=0;} server_names_hash_bucket_size 64; server { listen 80; listen [::]:80 default_server ipv6only=on; root /home/deploy/example/public; server_name example.com page.example.com; location / { proxy_pass http://unix:/home/deploy/example/shared/sockets/puma.sock; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } error_page 404 /404; error_page 500 /500; }

EDIT : I've changed the routes, added curl response and added nginx config.