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

http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;
access_log  /var/log/nginx/access.log  main;
sendfile        on;

upstream mongrel_cluster_example1 {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}

upstream mongrel_cluster_example2 {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
}

# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;

server {
listen       80;
server_name  example1.com example2.net;
client_max_body_size 120M;

set $myroot /var/www/html;
if ($host ~* example1\.com$) {
set $myroot /home/example1/public;
}

if ($host ~* example2\.net$) {
set $myroot /home/example2/public;
}

root $myroot;

location ~* ^/(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)$
{
root $myroot;
}

location / {

if ($host ~* example1\.com$) {
proxy_pass      http://mongrel_cluster_example1;
} #if check for domain qa.teenangel ends here

if ($host ~* example2\.net$) {
root /home/hoo/online-ordering/public;
proxy_pass      http://mongrel_cluster_example2;

} #if check for domain ends here

}

}

}

About these ads
This entry was posted in PHP and tagged , by Purab Kharat. Bookmark the permalink.

About Purab Kharat

I am WordPress and Drupal Architect. I worked on many technologies like Ruby on Rails, Flex, PHP etc... I am Purab Kharat from India, Pune. I love to play chess and listen music and read books. I work in SY Smartsourcing Global Pvt Ltd in Princeton, NJ, USA. Now I am living at Plainsboro, 164 Hampshire Drive, Princeton Meadows, NJ. I have more then Eight years experience in Web Application Development (Specially in Php 5.0, Ruby on Rails, Mysql 5.0, RIA, Wordpress, Drupal, Joomla, Ecommerce)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s