Project

General

Profile

Docs ModProxyCore » History » Revision 14

Revision 13 (hoffie, 2006-12-18 19:06) → Revision 14/51 (jan, 2006-12-19 05:02)

{{{ 
 #!rst  

 =================== 
 the Proxy Interface 
 =================== 

 ---------------------- 
 Module: mod_proxy_core 
 ---------------------- 

 .. contents:: Table of Contents 


 Description 
 =========== 

 FastCGI, SCGI, HTTP, ... are doing the simple job: they forward the HTTP-request to a backend and send the response back to the server. They just use another protocol to encode the data. 

 * FastCGI was developed by http://www.fastcgi.com/ and is a binary container around HTTP requests which reduces the parsing overhead. Options 
 * SCGI similar to HTTP and only adds a length header for ======= 

 lighttpd provides the HTTP-header. http://www.mems-exchange.org/software/scgi/ says "The SCGI protocol is a replacement for the Common Gateway Interface (CGI) protocol. It is a standard for applications to interface with HTTP servers. It is similar to FastCGI but is designed to be easier to implement." 
 * for HTTP we Proxy support HTTP/1.0 and HTTP/1.1 on via the backend side 
 * AJP13 is proxy-module  
 (mod_proxy_core) which provides the Apache JServ Protocol version 1.3 (see http://tomcat.apache.org/connectors-doc/common/ajpv13a.html), implemented by mod_jk following options in the apache world. config-file: 

 A small guide shall help you to choose the right protocol for your needs. 

 ======== ============= =============== ========== 
 Protocol preferred by    binary protocol keep-alive 
 ======== ============= =============== ========== 
 HTTP       mongrel         no                yes 
 SCGI       WSGI (python) not really        no 
 FastCGI    PHP, rails      yes               yes 
 AJP13      Tomcat          yes               don't know 
 ======== ============= =============== ========== 

 Installation 
 ------------ 

 If you want to use mod-proxy-core you have to load it first. Each protocol is a module too and has to be loaded 
 after the core-module.: :: 

   server.modules = ( 
     ...,  
     "mod_proxy_core", 
     "mod_proxy_backend_http", 
     ... ) 

 Options 
 ======= 

 proxy-core.balancer 
   might be one of 'round-robin', 'sqf' or 'carp'. 

 proxy-core.protocol 
   might be one of 'http', 'fastcgi', 'ajp13' 'fastcgi' or 'scgi'.    Make sure you load the backend 
   modules (see mod_proxy_backend_<name>) mod_proxy_backend_http/mod_proxy_backend_fastcgi/mod_proxy_backend_scgi/mod_proxy_backend_ajp13) 

 proxy-core.backends 
   tell the module where to send Proxy requests to. 
   It is a list of hostname/ip address/unix-domain socket 

 proxy-core.max-pool-size 
   max size for pool of connections to backends. 

 proxy-core.check-local 
   enable checking for url file in local document-root.    Enable this for php 

 proxy-core.allow-x-sendfile 
   enables use of "X-Sendfile/X-LIGHTTPD-Sendfile/X-LIGHTTPD-send-tempfile" headers. 

   See:  

     * http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support 
     * http://blog.lighttpd.net/articles/2006/11/29/faster-fastcgi 

 proxy-core.allow-x-rewrite 
   enables use of "X-Rewrite" 

   See: 
     * http://blog.lighttpd.net/articles/2006/07/22/x-sendfiles-new-friend-x-rewrite 

 


 proxy-core.rewrite-request 
   rewrite request headers or request uri. 

 proxy-core.rewrite-response 
   rewrite response headers. 

 Example: 
 ======== 

 Using lighttpd + mod_proxy_core in front of 8 Squids which handle the  
 caching of dynamic content for you. All requests for the host  
 www.example.org should be forwarded to the proxy. All proxies 
 listen on port 80 for requests. :: 

   server.modules    += ( "mod_proxy_backend_http" ) 
   $HTTP["host"] == "www.example.org" { 
     proxy-core.protocol = "http" 
     proxy-core.balancer = "carp" 
     proxy-core.backends = ( "10.0.0.10", 
                             "10.0.0.11", 
                             "10.0.0.12", 
                             "10.0.0.13", 
                             "10.0.0.14", 
                             "10.0.0.15", 
                             "10.0.0.16", 
                             "10.0.0.17" ) 
   } 

 If one of the hosts goes down the all requests for this one server are  
 moved equally to the other servers. If you want to know more about 
 the algorithm used here google for 'Microsoft CARP'. 

 for php using unix-domain socket "/tmp/php-fastcgi.sock" :: 

   server.modules    += ( "mod_proxy_backend_fastcgi" ) 
   $HTTP["url"] =~ "\.php$" { 
     proxy-core.balancer = "round-robin" 
     proxy-core.protocol = "fastcgi" 
     proxy-core.check-local = "enable" 
     proxy-core.allow-x-sendfile = "enable" 
     proxy-core.backends = ( "unix:/tmp/php-fastcgi.sock" ) 
     proxy-core.max-pool-size = 16 
   } 

 for SCGI :: 

   server.modules    += ( "mod_proxy_backend_scgi" ) 
   $HTTP["url"] =~ "\.scgi$" { 
     proxy-core.balancer = "round-robin" 
     proxy-core.protocol = "scgi" 
     proxy-core.check-local = "enable" 
     proxy-core.allow-x-sendfile = "enable" 
     proxy-core.backends = ( "127.0.0.1:9090" ) 
     proxy-core.max-pool-size = 16 
   } 

 for http-proxy with host and file-extension conditionals :: 

   server.modules    += ( "mod_proxy_backend_http" ) 
   $HTTP["host"] == "www.example.org" { 
     proxy-core.protocol = "http" 
     proxy-core.balancer = "carp" 
     $HTTP["url"] =~ "\.php$" { 
       proxy-core.backends = ( "10.0.0.10:80" ) 
     } 
     else $HTTP["url"] =~ "\.scgi$" { 
       proxy-core.backends = ( "10.0.0.11:80" ) 
     } 
   } 

 Reverse-Proxying :: 

   server.modules    += ( "mod_proxy_backend_http" ) 
   $HTTP["url"] =~ "^/proxyme(/|$)" { 
     proxy-core.balancer = "round-robin" 
     proxy-core.protocol = "http"  
     proxy-core.backends = ( "en.wikipedia.org" ) 
     proxy-core.rewrite-response = ( 
       "Location" => ( "^http://en.wikipedia.org/(.*)" => "http://127.0.0.1:1025/proxyme/$1" ), 
     ) 
     proxy-core.rewrite-request = ( 
       "_uri" => ( "^/proxyme/?(.*)" => "/$1" ), 
       "Host" => ( ".*" => "en.wikipedia.org" ), 
     ) 
   } 

 for proxying to Tomcat using AJP13 protocol :: 

   server.modules    += ( "mod_proxy_backend_ajp13" ) 
   $HTTP["url"] =~ "^/tomcat/" { 
     proxy-core.balancer = "round-robin" 
     proxy-core.protocol = "ajp13" 
     proxy-core.backends = ( "localhost:8009" ) 
     proxy-core.max-pool-size = 16 
   } 

 }}}