Apache host header proxy - apache

I have multiple urls coming into a server. I want to user host headers to redirect the traffic. I am trying to use Apache to redirect these requests to various servers that are inside our firewall. I have gotten part of the solution, but, I seem to be missing something.
For example, http://hostHeader1.mycompany.com should be redirected to a server inside our firewall that handles requests for hostHeader1, and the result should be handed back to the client. http://hostHeader2.mycompany.com should be redirected to a server inside our firewall that handles requests for hostHeader2. Etc.
Right now, I have the following, but, it redirects all traffic to http://hostHeader1Handler/:
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://hostHeader1Handler/
ProxyPassReverse / http://hostHeader1Handler/
ServerName hostHeader1.mycompany.com
</VirtualHost>
Any help appreciated.
Scott

This is probably your first or your only virtual host. Just add another virtual host before. Then this should be the new default.
NameVirtualHost *:*
<VirtualHost *:*>
ServerName your.default.domain.de
DocumentRoot /var/www/pathToHTML
</VirtualHost>
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://hostHeader1Handler/
ProxyPassReverse / http://hostHeader1Handler/
ServerName hostHeader1.mycompany.com
</VirtualHost>

Related

Gogs.io running on subdomain with port

I'm trying to run Gogs.io on an apache webserver along with a standard website, and I'm trying to have Gogs.io used on a subdomain rather than using my standard domain with a port.
Gogs.io runs on port 3000, and I want the url to be
http://gogs.example.net/
Rather than
http://example.net:3000/
Both my public IP with port and example.net:3000 work, but when trying to use gogs.example.net, I always get an AT&T DNS Error Assist page. I'm not sure what I'm doing wrong, as I had it working earlier until I tried to change the name of the subdomain in my apache config, but I changed it back when I started having issues, to no luck.
Here is my Apache config for the page:
<VirtualHost *:80>
ServerName gogs.example.net
ProxyPreserveHost On
ProxyPass / http://example.net:3000/
ProxyPassReverse / http://example.net:3000/
</VirtualHost>
This may be impossible, but any help would be greatly appreciated!
Fixed the issue by adding an A record to my domain
A Record: git -> 111.222.333.444
As well as modified the VirtualHost settings to include the subdomain in the ProxyPass and ProxyPassReverse
<VirtualHost *:80>
ServerName gogs.example.net
ProxyPreserveHost On
ProxyPass / http://git.example.net:3000/
ProxyPassReverse / http://git.example.net:3000/
</VirtualHost>

Apache listen and redirect to a different port

I know this has been asked before, I used the highest rated question as a baseline, but I still can't get it to work.
I'm trying to host a website through an iocage jail in FreeBSD.
In my jail I'm hosting a domain called sub.domain.com. I've managed to get Apache to listen to a different port, 10080. So when I go to sub.domain.com:10080 I can access my website.
I would like to be able to go sub.domain.com and also access my website. As far as I understand, I need to redirect using mod_proxy to allow 80 -> 10080.
In httpd.conf I uncommented mod_proxy and added the following
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.sub.domain.com
ServerAlias sub.domain.com
ProxyPass / http://localhost:10080
ProxyPassReverse / http://localhost:10080
</VirtualHost>
This doesn't work for me, I still have to go to sub.domain.com:10080 to access my website.
Any tips?
EDIT: current config, also doesn't work
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName <jailip>
ServerAlias <jailip>
ProxyPass / http://<jailip>:10080
ProxyPassReverse / http://<jailip>:10080
</VirtualHost>

ProxyPass with a port in Apache Virtualhost does not work

I'm using WSO2 API Manager. I have fronted API Manager(tomcat) with an Apache HTTP Server.
For the URL api.abc.xyz.lk a public IP has been assigned. For that public IP a local IP which is 192.168.6.162 has been assigned. I have added a virtual-host to redirect all the http://api.abc.xyz.lk to http://192.168.6.162:9763/store.
What I'm trying to do here is redirect all the http://api.abc.xyz.lk requests to http://192.168.6.162:9763/store.
Below is the virtual-host block I use.
<Virtualhost *:80>
ServerName api.abc.xyz.lk
ServerAlias api.abc.xyz.lk
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://192.168.6.162:9763/store
ProxyPassReverse / http://192.168.6.162:9763/store
</Virtualhost>
The problem is
the URL that works is as below
http://api.abc.xyz.lk:9763/store
But actually what I want is
http://api.abc.xyz.lk
How can I fix this?
you need to modify this proxy pass
ProxyPass /store http://192.168.6.162:9763/store
ProxyPassReverse /store http://192.168.6.162:9763/store
this will do the trick..
make sure to enable the proxy ports in server, you can configure proxy ports by editing "catalina-server.xml" in $UES_HOME/repository/conf/tomcat/catalina-server.xml

Apache 2.2 and tomcat redirection for subdomains

I have two tomcat servers running in my machine and i want to use apache to redirect the traffic to each server depending on the subdomain.
My httpd.conf is:
<VirtualHost *:80>
ServerName dev.bo.example.com
ProxyPass / ajp://localhost:11009/bo/
ProxyPassReverse / ajp://localhost:11009/bo/
ProxyPassReverseCookiePath /bo/ http://localhost:11001/bo/
</VirtualHost>
<VirtualHost *:80>
ServerName dev.com.example.com
ProxyPass / ajp://localhost:10009/com/
ProxyPassReverse / ajp://localhost:10009/com/
ProxyPassReverseCookiePath /com/ http://localhost:10001/com/
</VirtualHost>
The problem is that the traffic is always direct to the first tomcat server despite the subdomain i use.
It seems that only the first virtual host match despite if i use:
http://dev.com.com.example.com/ or
http://dev.bo.example.com/
Does any know what i am missing here?
Finally, i found that i missed configuration i had to add
NameVirtualHost *:80
to the httpd.conf

Route two domains to same JBoss instance

I have two public websites (foo.com and bar.com) that are pointed to a hardware load balancer. This hardware forwards the traffic to my server as follows:
http://foo.com ==> port 7700
https://foo.com ==> port 7701
http://bar.com ==> port 7800
https://bar.com ==> port 7801
My server is currently an old iPlanet box that defines two virtual servers (foo.com for 7700, 7701 and bar.com for 7800, 7801). Since the load balancer forwards directly to these ports, everything works fine.
I now need to port these website to an Apache 2.2 + JBoss 6.0 configuration, and I'm currently at a loss as to what the best practice is to accomplish this.
I've already set up Apache to listen on my four ports (7700,7701,7800, 7801) and configured SSL for 7701,7801. I'm assuming it is preferred to let Apache handle the SSL handshakes and connections. I have set up 4 Virtual Host entries in Apache, as follows:
<VirtualHost *:7700>
DocumentRoot "/htdocs/foo.com"
ServerName foo.com
</VirtualHost>
<VirtualHost *:7701>
DocumentRoot "/htdocs/foo.com"
ServerName foo.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/foo.com.crt"
SSLCertificateKeyFile "/cert/foo.com.key"
</VirtualHost>
<VirtualHost *:7800>
DocumentRoot "/htdocs/bar.com"
ServerName bar.com
</VirtualHost>
<VirtualHost *:7801>
DocumentRoot "/htdocs/bar.com"
ServerName bar.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/bar.com.crt"
SSLCertificateKeyFile "/cert/bar.com.key"
</VirtualHost>
I've tested this with static content, and both the HTTP and HTTPS connections are working correctly.
For my JBoss configuration, I currently have my applications deployed as /foo and /bar, although I don't know if that should be the final configuration. What I want to accomplish is this:
Forward all traffic from 7700/7701 to http://localhost:8080/foo, and from 7800/7801 to http://localhost:8080/bar. I don't want to see the /foo and /bar in the public URL, though - the user should just see http://www.foo.com and http://www.bar.com.
Is there a way to configure mod_jk to forward requests to a specific URL? Or should I be looking at ways to have JBoss host foo.com on port A and bar.com on port B -- and just have mod_jk forward to each port separately?
I think mod_jk combined with URL rewriting should handle what you need. The mod_jk information on workers indicates that you should be able to use mod_jk to forward requests based on URL using the uriworkermap. It's also mentioned that you can have a separate uriworkermap for each virtual host.
I'd also like to suggest that you take a look at mod_cluster - it might have additional capabilities that would help with this.
EDIT
Argh. After your clarification (and some better digging), I think there may be a different answer. I am currently using ProxyPass/ProxyPassReverse to redirect top-level URLs to individual servlets. I've reviewed the Apache VirtualHost docs again, and I think that if you combine that with mod_proxy, you'll be able to get what you want.
Here's a proposed configuration example that builds on what I have and could meet your specifications:
Listen 7700
Listen 7701
Listen 7800
Listen 7801
<VirtualHost *:7700>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName foo.com
</VirtualHost>
<VirtualHost *:7701>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName foo.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/foo.com.crt"
SSLCertificateKeyFile "/cert/foo.com.key"
</VirtualHost>
<VirtualHost *:7800>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName bar.com
</VirtualHost>
<VirtualHost *:7801>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName bar.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/bar.com.crt"
SSLCertificateKeyFile "/cert/bar.com.key"
</VirtualHost>
I apologize for missing this the first time. The only thing you'll want to test is to make sure that the URLs for servlet access are correct. The pattern I have in use is http://{host}:{port}/{WARName}/{ServletPath}. If you've already tested the configuration with static content, only the proxy setup should need to be added/tuned. I'm not sure if you'll need the Listen statements or not; I think you will, as your ports are non-standard.