Proxy configuration to load all images from a folder - reverse-proxy

I am using Magnolia 5.4 and i am trying to provide proxy pass settings to magnolia pages using apache http server. And i have configured like this
ProxyPass /travel http://<ip address>:8080/magnoliaPublic/travel.html
ProxyPass /.resources/** http://<ip address>:8080/.resources/**
the travel configuration is working, but not giving images and css files. So need a configuration to load all images and files that have .resources in path. how can i achieve this? Thaks

I don't know how to load folders,but to load images you can use following configuration using ProxyPassMatch
ProxyPassMatch "^/(.*\.png)$" "http://<ip address>:8080/$1"
ProxyPassMatch "^/(.*\.jpeg)$" "http://<ip address>:8080/$1"
ProxyPassMatch "^/(.*\.jpg)$" "http://<ip address>:8080/$1"
ProxyPassMatch "^/(.*\.img)$" "http://<ip address>:8080/$1"
With the above configuration, the apache server forward the requests that have extensions .png, .jpeg, .jpg, .img to the specified url.
Refer http://httpd.apache.org/docs/trunk/mod/mod_proxy.html#proxypassmatch for more information

Related

Run script during HTTP request

I'm trying to make my own custom CDN to make my website and my clients websites load more quickly.
I thought of doing something like this:
The user uploads the files they want on the CDN to a /cdn folder in their hosting account.
The files aren't uploaded to the CDN straight away
The files are only uploaded when the file is requested using the CDN
So my question is, how can I cause a script to run during the HTTP request to allow the CDN to go and grab the file?
Can I do something like this using Apache? I'm using Apache web servers.
It seems to me that what you are trying to do is essentially have servers load files from one primary server. I would recommend not running a script but using the CDN servers as proxies which cache the responses.
You would have to setup something like this in your apache (virtual)host directive.
ProxyRequests off
ProxyPass / http://backend.example.com/
ProxyPassReverse / http://backend.example.com/
CacheRoot /var/cache/apache/
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
See these entries:
mod_cache
mod_proxy
htcacheclean
Hope that helps!

Configuring Apache HTTP server with JBoss cartridge on Openshift

I am using JBoss/Tomcat + Mysql cartridges.
I would like to serve static resources (css,js,images) using Apache and host those files outside the WAR.
I would also like to be able to use Apache to configure redirect rules etc. Is there a way to do that? Thanks
You can not edit the vhost for your application, nor access the apache configs for your application when using one of the java cartridges. An apache proxy sits in front of your application, but is not accessible by you. You would either need to run a second gear with the php cartridge and host your static assets there, or try using a third party CDN to host your static files (such as amazon s3 or cloudfront). But with just using one of the java cartridges on OpenShift Online, you can not configure it the way that you are trying to.
You can do this as below. Put images, js & Css folder in Virtualhost document root. And call tomcat with help of mod_proxy_ajp configuration listed below.
ProxyPass /images !
ProxyPass /js !
ProxyPass /css !
ProxyPass / ajp://localhost:9009/
ProxyPassReverse / ajp://localhost:9009/

Apache ProxyPass doesn't work for multiple levels of path and enable proxypass for subdomains

I have two problems in setting Proxypass. I have setup the Proxypass in my Apache settings.
for example:
ProxyPass / http://www.domainname.com:8080/
ProxyPassReverse / http://www.domainname.com:8080/
I have the ROOT webapp in my tomcat to handle all the requests.
The following links work no problem:
http://www.domainname.com:8080/anypath1/anypathxxx
http://www.domainname.com:8080/anypath2/anypathxxx
but the followings to Apache do not work:
http://www.domainname.com/anypath1/anypathxxx
http://www.domainname.com/anypath2/anypathxxx
How do I fix the setting?
Another problem:
How do I setup wildcard proxypass for subdomains so that:
http://zzz.domainname.com/anypath1/anypathxxx proxypass to http://zzz.domainname.com:8080/anypath1/anypathxxx?
Thanks a lot in advance!!
I'am massively using Apache to loadbalance lots of Tomcats. I would strongly recommend mod_jk Apache Tomcat Connector for this case/job -> link. It is really easy to setup and truly stable!
Just install it from a repository, download binary (Windows) or build it from source.
Afterwards follow the quick start tutorial -> link
Also your second question (wildcards) could be solved this way.

Apache reverse proxy and load balancer - does not work as it should

I have 3 machines.
One (loadbalance.lan) is used as a load balancer, the other two (172.16.30.5 and 172.16.30.6) are tomcat's servers. Main page of the tomcat is listening on port 8080
Im typing in the browser loadbalance.lan/tomcat and I am able to see one of the tomcat content (default tomcat page)
The problem is page isn't displayed correctly. There's no images and when I click on any link it displays 404 Not found error.
Lets say I want to access one of the sub pages on the tomcat website. Tomcat website address: 172.16.30.5:8080
Now I can choose, lets say "status" link which redirects me to: 172.16.30.5:8080/manager/status (and works fine)
When I access the same page but via reverse proxy server (loadbalance.net) and click that link on the loadbalance.lan page, links redirect me to loadbalance.lan/manager/status and I get 404 error.
Of course when I type in the browser loadbalance.lan/tomcat/manager/status it displays correct.
Problem with the images is also weird. When I use url: loadbalance.lan/tomcat I can't see images (Tomcat logo)
When I use this one: loadbalance.lan/tomcat/ (slash at the end) it's ok. At least images because links still redirect in wrong place.
Here is my loadbalance.lan apache config:
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<VirtualHost *:80>
ProxyRequests Off
ProxyVia On
ProxyPreserveHost On
<Proxy balancer://cluster>
Order Deny,Allow
Allow from all
</Proxy>
<Proxy balancer://cluster>
BalancerMember http://172.16.30.5:8080
BalancerMember http://172.16.30.6:8080
<Proxy balancer://cluster>
</Proxy>
<Location /tomcat>
ProxyPass balancer://cluster
ProxyPassReverse balancer://cluster
</Location>
</VirtualHost>
Could someone help me with this?
Obviously there is something wrong with that proxy but I have no idea how to fix that :(
From ProxyPassReverse documentation (strong added):
This directive lets Apache adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses. This is essential when Apache is used as a reverse proxy (or gateway) to avoid by-passing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.
Only the HTTP response headers specifically mentioned above will be rewritten. Apache will not rewrite other response headers, nor will it rewrite URL references inside HTML pages. This means that if the proxied content contains absolute URL references, they will by-pass the proxy. A third-party module that will look inside the HTML and rewrite URL references is Nick Kew's mod_proxy_html.
So, the proxy job is not to rewrite the html content of the pages, if the proxyied content does not know that the final url should contain /tomcat extension and the proxy does not alter the pages... you're stuck.
This is usually something you do not see because the 172.16.30.5:8080 part is well rewritten in localhost.lan, but this rewrite is not made by the proxy, quite certainly because urls are in fact only relative (<img src="/foo/bar.png">). Check the source code of the page to see if the domain name is really rewritten in urls).
There's several ways of handling that:
- You could avoid altering relative urls paths in, the proxy (so not using a tomcat/ prefix, but instead a dedicated virtualhost with a name, like tomcat.lodabalncer.lan).
- You could also use some dedicated tools, like mod_proxy_html to rewrite the content of the pages, but that's a slow and complex thing.
- The third way is to manage the final full url on the application side (here tomcat) and detect the proxy chain elements in X-Forwareded-for Header to rebuild the right domain.
- Some applications provides tools for that, like the VirtualHostMonster in Zope
For tomcat the preferred tool is mod_proxy_ajp and not mod_proxy. But for a load balancer proxy I do not think you can use mod_proxy_ajp. And, it's been a long time since I made this, but in my memory I think mod_jk was the solution to that.
Read this full documentation on tomcat proxying for details. At least you should get some hints for the solution.

Apache Mod-rewrite across domains?

OK, I have a site, at www.domain.com. I added a web app on heroku and it has it Heroku URL and a custom domain. However, what I'd like to do is have it accessible via those two URL but on the www.domain.com site, I'd like to access that new server via www.domain.com/customapp. I figured I could do it through URL rewrite. But all the examples I see are doing the the other way, so is my idea possible? Is mod-rewrite the way to go?
Thanks.
Why don't you try setting up a reverse proxy for www.domain.com? Assuming you are using Apache 2.2, it's pretty easy to do if you have access to the httpd.conf or httpd-vhosts.conf file.
In your case I would add the following to your httpd.conf or httpd-vhosts.conf file.
ProxyRequests Off
ProxyPass /customapp/ <URL-to-Heroku-App>
ProxyPassReverse /customapp/ <URL-to-Heroku-App>
For more information, see the docs.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse