Apache httpd.conf – Virtual hosts port

Posted on

Problem :

I have an Apache Webserver running, which is reachable over the ip/port-combination 123.456.789:9000 from my browser.

Also I have a GitLab instance running on the ip/port-combination 123.456.789:8888 and a GitLab module named KanBan on 123.456.789:8889.

If someone requests the website 123.456.789:9000/gitlab I want the Apache Webserver to route the request to 123.456.789:8888.

Respectively If someone requests 123.456.789:9000/kanban I want the Apache Webserver route to 123.456.789:8889.

So instead of opening the ports 8888 and 8889 directly I want the Apache Webserver to function as a tunnel, which binds the two adresses to different ports internally while the ip remains the same.

I read that this kind of configuration is done inside httpd.conf and involses adding so called virtual hosts therein. Also it could involve some Linux specific routing via bind command.

Is this correct and if so can someone point me in the right direction of how to adpat the httpd.conf file?

If this is not possible how could I nevertheless configure it on my CentOs 7.1 Server?

Before cross-posting this on https://serverfault.com/ could an Administrator/Mod do it?

I have found this https://stackoverflow.com/questions/8541182/apache-redirect-to-another-port and it looks like its the same use case, but i am still trying it out.

After checking in with people in the IRC Channel #httpd, I was told that Apache Reverse Proxies should do the trick and was given this resource, http://www.apachetutor.org/admin/reverseproxies, which i am currently working on.

Solution :

Assuming you have a simple httpd configuration, a neat way to implement what you are looking for would be:

  • Create a file named /etc/httpd/conf.d/gitlab.conf with the contents:

    ProxyPass "/gitlab" "http://123.456.789:8888"
    ProxyPassReverse "/gitlab" "http://123.456.789:8888"
  • Create another file named /etc/httpd/conf.d/kanban.conf with the contents:

    ProxyPass "/kanban" "http://123.456.789:8889"
    ProxyPassReverse "/kanban" "http://123.456.789:8889"
  • Restart httpd.

I hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *