Apache – How to Redirect Port

apache-2.2port-forwardingredirect

I know there's a ton of answers to this question out there, but somehow none of them helped me. I have an Ubuntu running 3 webapps, each on different port (8080-8282) – jira, confluence and one more. Now I bought a domain name and bound three subdomains with the IP address of my server, the problem is they all point to the same IP address and to port 80. So I guess I need Apache server now. Now what I want apache to do is to redirect:

Preferably so it won't show the port. From my understanding I should add some lines to /etc/apache2/httpd.conf, and so I tried (this is literally my whole /etc/apache2/httpd.conf):

RewriteEngine on
RewriteCond %{HTTP_HOST} http://jira.mydomain.com/
RewriteRule ^(.*)$ http://jira.mydomain.com:8181 [L,R]
RewriteCond %{HTTP_HOST} http://wiki.mydomain.com/
RewriteRule ^(.*)$ http://wiki.mydomain.com:8080 [L,R]

But it doesn't work (whenever I try for example wiki.mydomain.com I get the default Apache site). So what am I missing here? (I know that to be able to hide the port number I'll have to use a proxy but first I just want to enable the redirect).

Best Answer

I would attempt to use apache in this way

Use Vhosts and mod_proxy

its quite rough ( dont expect to cut and paste ) :)

<VirtualHost jira.mydomain.com:*>
ProxyPreserveHost On
ProxyPass / http://jira.mydomain.com:8181/
ProxyPassReverse / http://jira.mydomain.com:8181/
ServerName jira.mydomain.com
</VirtualHost>

<VirtualHost wiki.mydomain.com:*>
ProxyPreserveHost On
ProxyPass / http://wiki.mydomain.com:8080/
ProxyPassReverse / http://wiki.mydomain.com:8080/
ServerName wiki.mydomain.com
</VirtualHost>
Related Topic