One rail application for multiple domain names

I have one rail application that needs to be deployed by the nginx passenger module. This application must be served by hundreds of domain names. I don't have enough memory to run hundreds of rails. I'm not sure that you can run rails in several cases. This is the same application under different domain names.

server {
    listen 80;
    server_name www.a_domain.com;
    root /webapps/mycook/public;
    passenger_enabled on;
}
server {
    listen 80;
    server_name www.b_domain.com;
    root /webapps/mycook/public;
    passenger_enabled on;
} 
server {
    listen 80;
    server_name www.c_domain.com;
    root /webapps/mycook/public;
    passenger_enabled on;
}

As you can with the above code, it launches three rail instances. It would be nice to run only a service instance in these three domains. Anyone have any suggestions?

+3
source share
2 answers

Just configure a few domain aliases for this server entry.

server {
    listen 80;
    server_name www.a_domain.com www.b_domain.com www.c_domain.com;
    root /webapps/mycook/public;
    passenger_enabled on;
}

, .

+7

, , .

server_name *;  # handle requests from all domains

Rails ( ).

" "

Nginx rails, . www.abc.com www.xyz.com . , .

, , . , , www.abc.com/about www.xyz.com/about .

" "

Nginx ""

Nginx rails. :

server_name *;  # handle requests from all domains
rewrite ^(?:www.)?([^.]*)\..*$ $1.yourdomain.com last;

. , xyz : www.xyz.com, xyz.com, xzy.co.uk, www.xyz.co.uk. xyz.yourdomain.com.

, Nginx , rails , . Page.where(subdomain: request.subdomain, permalink: params[:permalink]) .

, , . , , , . $1 , , URL. , yourdomain.com/$1 www.xyz.com yourdomain.com/xyz.

- " ". www.xyz.com, , xyz.yourdomain.com .

"Rails Way"

Rails ApplicationController

, , Rails request.

ApplicationController , . , domain_name:

def domain_user
  @domain_user ||= User.where(domain_name: request.domain()).take
end

Redis , . .

, www.xyz.com, xyz.com. , :

def domain_user
  request.domain.match /(?:www.)?(.*)/
  @domain_user ||= User.where(domain_name: $1).take
end

www. . ( Ruby $1).

Nginx, www.xyz.com, , .

" "

Rails 3 , , , . "-", . User ( ) , . , , , .

, , ApplicationController, . MCV.

0

Source: https://habr.com/ru/post/1762710/


All Articles