Apache redirect to another port Apache redirect to another port apache apache

Apache redirect to another port


You should leave out the domain http://example.com in ProxyPass and ProxyPassReverse and leave it as /. Additionally, you need to leave the / at the end of example/ to where it is redirecting. Also, I had some trouble with http://example.com vs. http://www.example.com - only the www worked until I made the ServerName www.example.com, and the ServerAlias example.com. Give the following a go.

<VirtualHost *:80>   ProxyPreserveHost On  ProxyRequests Off  ServerName www.example.com  ServerAlias example.com  ProxyPass / http://localhost:8080/example/  ProxyPassReverse / http://localhost:8080/example/</VirtualHost> 

After you make these changes, add the needed modules and restart apache

sudo a2enmod proxy && sudo a2enmod proxy_http && sudo service apache2 restart


I solved this issue with the following code:

LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_http_module modules/mod_proxy_http.so<VirtualHost *:80>ProxyPreserveHost OnProxyRequests OffServerName myhost.comServerAlias ww.myhost.comProxyPass / http://localhost:8080/ProxyPassReverse / http://localhost:8080/</VirtualHost>

I also used:

a2enmod proxy_http


I wanted to do exactly this so I could access Jenkins from the root domain.

I found I had to disable the default site to get this to work. Here's exactly what I did.

$ sudo vi /etc/apache2/sites-available/jenkins

And insert this into file:

<VirtualHost *:80>  ProxyPreserveHost On  ProxyRequests Off  ServerName mydomain.com  ServerAlias mydomain  ProxyPass / http://localhost:8080/  ProxyPassReverse / http://localhost:8080/  <Proxy *>        Order deny,allow        Allow from all  </Proxy></VirtualHost>

Next you need to enable/disable the appropriate sites:

$ sudo a2ensite jenkins$ sudo a2dissite default$ sudo service apache2 reload

Hope it helps someone.