A H K
A H K

Reputation: 1750

Rails app is not working with subdomain on production

I have an application developed on Rails4 and Ruby2 and i have an issue with this application on production. Actually i am redirecting every user to his subdomain and from there user can manage his account, but the problem is that App is working fine on the main domain like: www.domain.com but when user being redirected to his subdomain like: subdomain.domain.com then getting Server not found. and locally it is working fine with the help of lvh.me all subdimains and everything.

I am using Apache2+Passenger On server.

Is there anything which i have to change in my Apache config ?

<VirtualHost *>
    ServerName www.domain.com
    ServerAlias domain.com *.domain.com
    DocumentRoot /home/deploy/myapp/public
 <Directory /home/deploy/myapp/public>
        Allow from all
    </Directory>
</VirtualHost>

Thanks

Upvotes: 0

Views: 628

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

Middleware

I've found the best way to handle subdomains with Apache is to rely on the Rails middleware. It's not as efficient as I would like, but equally effective.

You can do this:

#etc/apache2/apache2.conf
<VirtualHost *:80>
    ServerName www.domain.com
    ServerAlias domain.com
    DocumentRoot /home/deploy/myapp/public
 <Directory /home/deploy/myapp/public>
        Allow from all
    </Directory>
</VirtualHost>

If you use a wildcard DNS setting for your subdomain, you'll be able to route all your incoming "subdomain" requests to your domain, allowing Rails to determine the routing based on the subdomain

Upvotes: 1

Related Questions