A
A
alexnotonfire2015-12-08 22:35:13
Nginx
alexnotonfire, 2015-12-08 22:35:13

How to handle requests for subdomains in a Rails application?

For example, I want my website URL to look like blog.mysite.com. How can I achieve this in Ruby on Rails? I am using nginx server.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kozhin, 2015-12-08
@kkzhn

You can, for example, write lines like this in the server section of the nginx configuration:

server {
...
    if ( $host != 'blog.mysite.com' ) {
        rewrite ^/(.*)$ http://blog.mysite.com/$1 permanent;
    }
...
}

For each subdomain, you need to create your own server section.
However, all these virtual hosts can even point to one Rail application. The application logic for each subdomain can be organized using the request.host variable .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question