[ start | index | login ]

mod_proxy

Created by david. Last edited by ivan, 319 days ago. Viewed 1,527 times. #5
[diff] [history] [edit] [rdf]
labels
attachments

Passing a Request To Another Server (or server process on same server)

Sometimes it's ideal to redirect a request for certain content to either another physical server or another process on the same physical server (e.g. a Mongrel process servicing Rails request). You can utilize mod_proxy to handle this via the following code:

#pass all requests coming into the root of the app to another process
ProxyPass        / http://www.yourdomain.com:8000/
ProxyPassReverse / http://www.yourdomain.com:8000/

#pass requests off to another physical server ProxyPass / http://www.otherserver.com/ ProxyPassReverse / http://www.otherserver.com/

This process should be transparent to the client making the request. The ProxyPassReverse directive ensures Apache will modify response headers so as to appear to be originating from the frontend server.

Using mod_proxy with Tomcat/Liferay

To serve your tomcat/liferay application through Apache, add the following inside your VirtualHost definition:

<VirtualHost *:80>
    ServerName example.com
    ProxyRequests Off
    ProxyPass / ajp://127.0.0.1:8009/
    ProxyPassReverse / ajp://127.0.0.1:8009/
</VirtualHost>

The code above would direct all your site's traffic to the tomcat/liferay installation, ie. >>http://example.com:8080/ and >>http://example.com/ would show the same content.

If you need to direct only one part of the site to a tomcat/liferay app, the code would look as follows:

ProxyPass /tomcat ajp://127.0.0.1:8009/
ProxyPassReverse /tomcat ajp://127.0.0.1:8009/

Or if you have more than one application running at the same time:

ProxyPass /tomcat ajp://127.0.0.1:8009/jsp-examples/
ProxyPassReverse /tomcat ajp://127.0.0.1:8009/jsp-examples/

Remember to add the trailing slashes to those ajp URLs!

Passing specific files to Tomcat

Allowing apache to host static content and Tomcat to host the dynamic content without touching the directory structures is useful.sometimes. To do this mod_proxy_ajp is used in conjunction with mod_rewrite like so:

RewriteEngine on
RewriteCond %{REQUEST_URI} /(.*).jsp|.muse|.do(.*)
RewriteRule ^/(.*) ajp://localhost:8009/$1 [P]

File name extensions are seperated with a `|`

请以发表评论身份登录
Powered by snipsnap.org Found a mistake in a howto? Let us know via an email to p.blikibugs at rimuhosting com.