How to host multiple rails site on Nginx

Nginx famous now. We given information for how to host multiple rails site on Nginx. we given the configuration code along with their detailed information.

How to host multiple rails site on Nginx

User following code in Nginx.conf file.. and paste into that file.
#vim /etc/nginx/nginx.conf

01http {
02include       /etc/nginx/mime.types;
03default_type  application/octet-stream;
04access_log  /var/log/nginx/access.log  main;
05sendfile        on;
06 
07upstream mongrel_cluster_example1 {
08server 127.0.0.1:8000;
09server 127.0.0.1:8001;
10server 127.0.0.1:8002;
11}
12 
13upstream mongrel_cluster_example2 {
14server 127.0.0.1:3000;
15server 127.0.0.1:3001;
16server 127.0.0.1:3002;
17}
18 
19# Load config files from the /etc/nginx/conf.d directory
20include /etc/nginx/conf.d/*.conf;
21 
22server {
23listen       80;
24server_name  example1.com example2.net;
25client_max_body_size 120M;
26 
27set $myroot /var/www/html;
28if ($host ~* example1\.com$) {
29set $myroot /home/example1/public;
30}
31 
32if ($host ~* example2\.net$) {
33set $myroot /home/example2/public;
34}
35 
36root $myroot;
37 
38location ~* ^/(images|stylesheets|javascripts).+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
39{
40root $myroot;
41}
42 
43location / {
44 
45if ($host ~* example1\.com$) {
46proxy_pass      http://mongrel_cluster_example1;
47} #if check for domain qa.teenangel ends here
48 
49if ($host ~* example2\.net$) {
50root /home/rail_project/myproject/public;
51proxy_pass      http://mongrel_cluster_example2;
52 
53} #if check for domain ends here
54 
55}
56 
57}
58 
59}

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.