Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 28th, 2008, 09:41 AM
g_hadgraft g_hadgraft is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 162 g_hadgraft User rank is Private First Class (20 - 50 Reputation Level)g_hadgraft User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 9 h 9 m 29 sec
Reputation Power: 4
Mongrel and domains.

My hand has been forced to have the follwoing setup.

I have a dedicated server which uses iis for serving up websites. There are 4-5 websites which all have different domains but share the same ip. However recently i have got interested in ruby. I know have an application ready which i want to put on to this server, however i cant get the ruby implementation working with iis.

So i am planning on using mongrel at the moment. I have the application working with mongrel and can browse to it correctly by going to say port 3000. However the problem is that the rest of the domains can also goto the application by going to port 3000.

Is there a way to get mongrel to bind to a domain rather than an ip.

I hope that all makes sense thanks for any help.

Reply With Quote
  #2  
Old March 28th, 2008, 01:44 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,440 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 50 m 56 sec
Reputation Power: 797
You can set up multiple domains by using ngnix and mongrel (or) apache and mongrel.

This is how I do it:
1. Set up mongrel for each domain to listen on a different set of ports. For instance, on domain1, I have mongrel listening on 8000, 8001 and 8002. On domain 2, I have mongrel listening on 9000, 9001 and 9002

2. Set up ngnix (or apache) to listen on port 80 and have it forward the requests for each domain up to the appropriate set of mongrels.

3. Profit.

As to why I set mongrels to listen on 8000...8002 and 9000...9002, that's because I also have them set with production environment on those ports (so no debug error messages are sent to the user). If I have an error suddenly occurring, I start up another instance on port 3000 with debugging on and check what the message is .

For your benefit, I'm adding my mongrel_cluster.yml and nginx.conf files.

mongrel_cluster.yml for domain1.com
Code:
user: wwwuser
cwd: /home/wwwuser/rails/domain1
log_file: log/mongrel.log
port: "8000"
environment: production
group: wwwuser
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 3


mongrel_cluster.yml for domain2.com
Code:
user: wwwuser
cwd: /home/wwwuser/rails/domain2
log_file: log/mongrel.log
port: "9000"
environment: production
group: wwwuser
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 3


Note that for domain1.com, I also own domain1.net and domain1.org and I have two separate rules to redirect domain1.net and domain1.org back to domain1.com in my nginx.conf file.

nginx.conf file
Code:
user  wwwuser wwwuser;
worker_processes  6;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] $status '
                      '"$request" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;

        gzip  on;
    upstream mongrel1 {
     server 127.0.0.1:8000;
     server 127.0.0.1:8001;
     server 127.0.0.1:8002;
    }

    upstream mongrel2 {
     server 127.0.0.1:9000;
     server 127.0.0.1:9001;
     server 127.0.0.1:9002;
    }

    #Rails App here
    server {
        listen       80;
        root /home/wwwuser/rails/domain1/public;
        index index.html index.htm;
        server_name www.domain1.com domain1.com; 
        client_max_body_size 110K;

        access_log  /var/log/nginx/domain1.access.log;

        location / {
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded_for $proxy_add_x_forwarded_for;
         proxy_set_header Host $http_host;
         proxy_redirect false;
         proxy_max_temp_file_size 0;

         if (-f $request_filename) {
            break;
          }
         if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
         }
         if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
         }
         if (!-f $request_filename) {
            proxy_pass http://mongrel1;
            break;
         }

        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /500.html;
        location = /500.html {
            root  /home/wwwuser/rails/domain1/public;
        }
    }

    # Redirect domain1.org to domain1.com
    server {
        listen 80;
        server_name domain1.org www.domain1.org;

        rewrite ^/(.*)$ http://www.domain1.com/$1 permanent;
    }

    # Redirect domain1.net to domain1.com
    server {
        listen 80;
        server_name domain1.net www.domain1.net;

        rewrite ^/(.*)$ http://www.domain1.com/$1 permanent;
    }



    server {
        listen       80;
        root /home/wwwuser/rails/domain2_newer/public;
        index index.html index.htm;
        server_name www.domain2.com domain2.com dev.domain2.com beta.domain2.com; 
        client_max_body_size 110K;

        access_log  /var/log/nginx/domain2.access.log;

        location / {
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded_for $proxy_add_x_forwarded_for;
         proxy_set_header Host $http_host;
         proxy_redirect false;
         proxy_max_temp_file_size 0;

         if (-f $request_filename) {
            break;
          }
         if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
         }
         if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
         }
         if (!-f $request_filename) {
            proxy_pass http://mongrel2;
            break;
         }

        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /500.html;
        location = /500.html {
            root  /home/wwwuser/rails/domain2_newer/public;
        }
    }



}
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Mongrel and domains.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway