(Using phusion passenger + Nginx) running same rai

2019-05-27 03:03发布

Note : i am newbie to ruby on rails and server hosting , i unable to express my vision as question , please forgive me if i am wrong or correct me.

Hi , i am having an one product developed using ruby on rails , going to host in an dedicated server with 32 GB Ram and 8 Core Server Processor. Each client should have seperate DB and separate rails instance. I am replicating - duplicating code for each client with separate folders and giving different database names and so each serving as an different instance.

For Example:

I am having one primary temp domain

www.product.com

For each client i need to have separate sub domain mapped to same server with same port(80) but with different rails instance name

www.client1.product.com
www.client2.product.com
www.clientn.product.com

As i know if i start rails instance , each will start at seperate port no's

client1 with start at port 3001
client2 with start at port 3002
client3 with start at port 3003

What my question is how do i map all the instances with port 80 with appropriate identical sub domains

if i access

www.client4.product.com , i need to get app running in port 3004

Update:

Can anyone please post steps for phusion passenger + Nginx for the above scenario

2条回答
SAY GOODBYE
2楼-- · 2019-05-27 03:18

With Phusion Passenger + Apache, the easiest way to achieve what you want is using VHOST.

Just checkout your project in different folders :

  • /var/www/rails/client1/
  • /var/www/rails/client2/
  • /var/www/rails/client3/
  • /var/www/rails/client4/

Then make a VHOST file for each of your client in /etc/apache2/sites-available/client1.foobar.com

<VirtualHost *:80>
        ServerName client1.foobar.com
        DocumentRoot /var/www/rails/client1/current/public

        <Directory /var/www/rails/client1/current/public>
                Allow from all
                Options -MultiViews
        </Directory>

</VirtualHost>

Then you add that VHOST to the list of managed domain a2ensite client1.foobar.com

And you reload apache /etc/init.d/apache2 reload

I supposed you deployed using capistrano , that's why I added the "current" folder, but if you don't, just remove that part (and really think about adopting capistrano)

I also supposed your server is a linux box, but if it is not just read the doc of apache about reloading the config and adding a new VHOST (and really think about having a linux server)

PS : Oh and if you don't use capistrano and you make an update to your codebase, don't forget to touch the "tmp/restart" file inside you app directory to tell passenger to restart the rails process. But don't try to use the "rails server" command in production ;)

查看更多
We Are One
3楼-- · 2019-05-27 03:20

Here is a sample example of a minimal server block for nginx + passenger

server {
        listen 80;
        server_name client1.foobar.com;
        root /var/www/rails/client1/current/public;

    passenger_enabled on;
}

The usual way of configuring nginx is to make a subdirectory "sites-available" where you put a file named "client1.foobar.com" containing this snippet , then make a symbolic link for this file in another subdirectory named "sites-enabled". Finally you add the following line in you nginx.conf inside the http block

include /path/to/your/sites-enabled/*;

Do not forget to reload/restart your nginx.

This way of using symbolic link allows you to easily disable any site you want by deleting the symbolic link without losing your config file.

You can find some example and more documentation here : http://www.modrails.com/documentation/Users%20guide%20Nginx.html

查看更多
登录 后发表回答