[ Pobierz całość w formacie PDF ]

as well as other proxying techniques, at http://www.apacheweek.com/features/
reverseproxies.
If an entire virtual host is to be proxied to another server, the syntax would look very
similar to that presented earlier:
ProxyPass / http://other.example.com/
ProxyPassReverse / http://other.example.com/
Placing these rules inside a virtual host or in the main server configuration file will
cause that entire host to be served from the other server, via the proxy mechanism.
Once you start doing this kind of global proxying, the most common question to
come up is how you can exclude certain things from this proxying. That s where
mod_rewrite comes in.
5610_c11_final.qxd 1/10/06 1:04 AM Page 117
CHAPTER 11  % PROXYING 117
Proxying with mod_rewrite
mod_rewrite should be used for proxying when the structure of the content to be proxied
is more complex than simply a directory or an entire virtual host. If a regular expression
pattern can be written to describe the content to be proxied, then mod_rewrite may be
the right solution to the problem.
I ll start with a few examples that exactly mirror the examples given in the earlier
non-mod_rewrite section. First, here s a RewriteRulethat causes proxying of the /images/
directory on a front-end server:
RewriteEngine On
RewriteRule ^/images/(.*) http://images.example.com/images/$1 [P]
ProxyPassReverse /images/ http://images.example.com/images/
The ProxyPassReversedirective is still needed, for exactly the reasons cited before.
The [P]rewrite directive is passed off to mod_proxy, and so everything from that point
is exactly the same as if you had used a ProxyPassdirective.
To mimic the previous  proxy everything configuration, we d alter the rewrite rule
set in the expected way:
RewriteEngine On
RewriteRule (.*) http://other.example.com$1 [P]
ProxyPassReverse / http://other.example.com
However, neither of these rule sets are particularly useful, since, in each case, we
should have used ProxyPassinstead. Now let s consider a task where mod_rewrite is
much more useful.
Proxying a Particular File Type
In the first real example, imagine that we re trying to reduce the load on our web server
by offloading some of the content to a back-end server. As before, the imagesdirectory
will be moved to another server. Unfortunately, images are scattered throughout the
entire server directory structure, rather than all being conveniently located in one place.
Rather than trying to hunt down all of the images on the entire server, we ll just copy
the entire document directory to the back-end image server, and then we ll just proxy any
request that looks like an image. Over time, perhaps we can consolidate all of the images
in a single directory, but for now, we ll leave the structure as it is.
RewriteEngine On
RewriteRule (.*\.(jpg|gif|png)) http://images.example.com$1 [P]
ProxyPassReverse / http://images.example.com/
5610_c11_final.qxd 1/10/06 1:04 AM Page 118
118 CHAPTER 11  % PROXYING
In this case, the ProxyPassReversereally isn t necessary, since every request passed
to the back-end server will be a fully qualified request for a particular image file. How-
ever, since it s a good habit to be in, and doesn t hurt anything, let s leave that in there.
Any request for a file ending in jpg, gif, or pngwill be proxied to the back-end image
server, and, since the directory trees match, the image will be there. As more image files
are added to the server, a more logical structure for image placement may be followed,
eventually removing the need for this much complexity.
Proxying to an Application Server
When you re running Apache as an application server, you may find that this causes a
significant performance degradation. mod_proxy may be used to improve this situation
by segregating your static and dynamic content to different servers. The static content
can be served very quickly, while the dynamic requests are proxied to a back-end server
that runs only that content.
A fairly common configuration for this is to run that secondary server on the same
physical machine, but on another port. Consider, for example, a site powered by mod_perl.
The static content is served from the front-end server, but the mod_perl content is served by [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • oralb.xlx.pl