#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    173
    Rep Power
    10

    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.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo