I have multiple hostnames resolving to a single machine, e.g.:

  • build.mydomain.com
  • www.mydomain.com
  • jira.mydomain.com
  • mydomain.com

Is it possible to setup apache in order to redirect requests to each different hostname?

e.g:

  • build.mydomain.com -> build.mydomain.com:8111,
  • www.mydomain.com -> www.mydomain.com:8080
  • mydomain.com -> www.mydomain.com:8080

The DNS records are setup to all point to the same machine, i just want to redirect to the right port given the hostname.

Cheers,

Edit:

Machine is debian w/ Apache2

Edit2:

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    redirect 301 / http://www.mydomain.com:8080/
</VirtualHost>

<VirtualHost *:80>
    ServerName build.mydomain.com
    redirect 301 / http://build.mydomain.com:8111/
</VirtualHost>
link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

Are you running multiple instances of Apache, each listening on a different port? Why? Virtual hosts will take care of everything.

http://httpd.apache.org/docs/2.2/vhosts/name-based.html

link|improve this answer
No, single instance of apache that I wanted to use to redirect requests. Got multiple instances of tomcat running, e.g. TeamCity on 8111, tomcat on 8080 and JIRA on 8081. I wanted to redirect to the respective port given the hostname. – user30665 Jan 4 '10 at 5:10
how about mod-rewrite running on the apache:80 instance? possibly even apache as proxy but that sounds like far too much effort for a redirect. – MidnighToker Jan 4 '10 at 5:18
I have it half working, using VirtualHost directive with a redirect 301 to the same hostname and different port. This should do for now. Cheers, – user30665 Jan 4 '10 at 5:21
feedback

Actually, I doubt using redirect is winning strategy for what you're trying to do. I'd recommend using mod_proxy to create a reverse proxy which will hide the way you've built your system.

And if I had the choice, I would use something more lightweight and more convenient to configure, like Perlbal.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown