Author: ytfei
Date: 18:28:26
Original article. For more information, see the source! Http://blog.romebuilder.com/2011/01/273/
There are many related articles on the Internet about the concept of reverse proxy. This is an article in Baidu: http://baike.baidu.com/view/1165595.htm.
Jetty can communicate with httpd through HTTP or AJP. jetty officially recommends using HTTP for communication. The following are jetty-7.2.2, APACHE-HTTPd 2.2.13, and WINXP configurations:
1. Start the httpd proxy module. Modify the httpd. conf file and remove the following comments.
Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_http_module modules/mod_proxy_http.so
The httpd release on Windows XP comes with the mod_proxy module and does not need to be installed separately. On the Linux platform, you may need to start related compilation options.
2. Enable the request forwarding function. Add the following code to the httpd. conf file.
Proxyrequests off
<Proxy *>
Order deny, allow
Allow from all
</Proxy>
3. The proxied path must be specified in the configuration file. The complete jetty path must be provided. As follows:
Proxypass/test HTTP :/// localhost: 8080/test
4. Follow the instructions in the Apache httpd documentation to enableWith the proxypassreverse feature, httpd can rewrite the URL Information in the request message. Similarly, jetty provides URL rewriting. You can also enableThe proxypreservehost option allows you to use jetty's rewrite function. As follows:
Proxypreservehost on
If you want to retain the original host information in the request, you can set the forwarded attribute of jetty as follows:
<Configure id = "server" class = "org. Eclipse. Jetty. server. Server">
...
<Call name = "addconnector">
<Arg>
<New class = "org. Eclipse. Jetty. NiO. selectchannelconnector">
<Set name = "Port"> 8080 </set>
<Set name = "forwarded"> true </set>
</New>
</Arg>
</Call>
...
</Configure>
Alternatively, use the following settings to force all servletrequest. getremoteaddr () to return the same values. (Assuming that the HTTP request header is unavailable), you can make the following settings:
<Configure id = "server" class = "org. mortbay. Jetty. Server">
...
<Call name = "addconnector">
<Arg>
<New class = "org. mortbay. Jetty. NiO. selectchannelconnector">
<Set name = "Port"> 8080 </set>
<Set name = "forwarded"> true </set>
<Set name = "hostheader"> example.com: 81 </set>
</New>
</Arg>
</Call>
...
</Configure>
5. Start the httpd and jetty servers. When you access the http: // localhost/test path of httpd, the same content as http: // localhost: 8080/test is displayed.