Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Say I have a minimalist Python web server running with several instances, each with different ports specified as command line arguments.

I'd like requests to my server to be redirected like this, using the Host header:

name1.mydomain.com -> localhost:8000
name2.mydomain.com -> localhost:8001
name3.mydomain.com -> localhost:8002

Is this something best done with a server like Lighttpd and doing some virtualhost configuration - is that possible?

I'd prefer not to use something heavy weight like Apache.

Thanks!

share|improve this question

1 Answer 1

With nginx you could use something like following:

server {
  server_name name1.domain.com;
  location / {
    proxy_pass http://localhost:8000;
  }
}

server {
  server_name name2.domain.com;
  location / {
    proxy_pass http://localhost:8001;
  }
}

server {
  server_name name3.domain.com;
  location / {
    proxy_pass http://localhost:8002;
  }
}

BTW, there is another method to achieve same effect using map directive:

map $http_host  $port {
    hostnames;

    default               8000;
    name1.example.com     8000;
    name2.example.com     8001;
    name3.example.com     8002;
}

server {
    listen       80;
    server_name ~^name\d.example.com;
    location / {
        proxy_pass http://127.0.0.1:$port;
    }
}
share|improve this answer
    
Thanks, will accept this after I've tested it works :) –  Luke Stanley Jul 17 '11 at 3:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.