Advanced Webserver Setup for WebGUI WebGUI User Conference Chicago, October 2004 Leendert Bottelberghs, United Knowledge
Overview the WebGUI request Apache Server Serving Content Load Balancing Apache Proxy WebGUI Webserver
The WebGUI Request: what happens browser - server communication WebGUI::Page one request generates multiple
What happens with a WebGUI request? client/browser WebGUI Request server WG::Page return HTML
What happens with a WebGUI request? client/browser server WebGUI Request WG::Page WebGUI start session process operations process functions generate page return HTML
What happens with a WebGUI request? client/browser WebGUI Request render HTML server WG::Page return HTML
What happens with a WebGUI request? client/browser WebGUI Request render HTML server WG::Page return HTML <html> <link rel= stylesheet href= http://... > <body> <img src= http://... >.... </body> </html>
What happens with a WebGUI request? client/browser WebGUI Request render HTML file Request interpret file server WG::Page retrieve file return HTML return file
Apache Server: outlines Server Pool Min, Max & Spare Serving Content CGI vs mod_perl
Apache Server httpd httpd = busy = waiting main httpd process controls Server Pool httpd httpd httpd httpd httpd httpd httpd httpd httpd
Apache Server: pre-forking Configuration directives: MinSpareServers MaxSpareServers MaxClients Server Pool busy min spare max spare max clients
Serving Content internet client webserver HTTPD Process application? compi le yes no retriev e file execu te return respo nse compile cgi: on-the-fly mod_perl: at Apache startup
CGI vs mod_perl 1
Load balancing principles: distribute requests over different servers using WebGUI.conf using a Reverse Proxy Server
Balancing the load internet client application request file request Apache mod_perl Server lightweight webserver Use WebGUI.conf: uploadsurl=http://[domain]:[port] extrasurl=http://[domain]:[port]
Load balancing: advantages no unnecessary use of resources more processes available for static file requests -> faster serving ability to use different *physical* servers better performance
Load balancing with WebGUI.conf: drawbacks different hosts (URLs) for pages and static content; causes javascript security violations Apache/mod_perl suffers from client connection speed solution: Reverse Proxy Server
Using a Reverse Proxy Server internet client application request request Reverse Proxy Server file request URI translation Apache/mod_perl Server lightweight webserver
Reverse Proxy Server example internet client application request request file request port: 80 port: 3001 port: 3002 Reverse Proxy URI translation: if(/uploads/) -> http://mycompany.com:3002/uploads/ if(/extras/) -> http://mycompany.com:3002/extras/ else -> http://mycompany.com:3001/
Setup Apache as Proxy basic Apache modules examples combining Reverse Proxy and Static Content Servers
Using Apache as Proxy Server Modules: mod_rewrite -> URI translation mod_proxy -> reverse proxy request to different servers
Using Apache as Proxy Server Example httpd.conf - using different ports RewriteEngine on RewriteRule ^/uploads/(.*)$ to://%{http_host}:3002/uploads/$1 [S=2] RewriteRule ^/extras/(.*)$ to://%{http_host}:3002/extras/$1 [S=1] RewriteRule ^/(.*)$ to://%{http_host}:3001/$1 RewriteRule ^to://([^/])+/(.*) http://$1/$2 [E=SERVER:$1,P,L] RewriteRule.* - [F] ProxyRequests Off ProxyPassReverse / http://%{http_host}/
Using Apache as Proxy Server Example 2 httpd.conf - using RewriteMap RewriteEngine on RewriteMap static txt:/some/location/static-servers.map RewriteMap dynamic txt:/some/location/dynamic-servers.map RewriteRule ^/uploads/(.*)$ to://${static:%{http_host}}/uploads/$1 [S=2] RewriteRule ^/extras/(.*)$ to://${static:%{http_host}}/extras/$1 [S=1] RewriteRule ^/(.*)$ to://${dynamic:%{http_host}}/$1 RewriteRule ^to://([^/])+/(.*) http://$1/$2 [E=SERVER:$1,P,L] RewriteRule.* - [F] ProxyRequests Off ProxyPassReverse / http://%{http_host}/
Using Apache as Proxy Server Example 2 static-servers.map mycompany.com webgui.com mycompany.com:3001 static.webgui.com dynamic-servers.map mycompany.com webgui.com mycompany.com:3002 dynamic.webgui.com
Reverse Proxy & static content Servers Combined internet client request application request Reverse Proxy / static content Server FS file request Apache/mod_perl Server
RProxy & SC Server combined: Example httpd.conf RewriteEngine on RewriteMap dynamic txt:/some/location/dynamic-servers.map RewriteCond %{REQUEST_URI} ^/(uploads extras)/ RewriteRule ^/(.*)$ /home/public/%{http_host}/www/$1 [E=SERVER:%{HTTP_HOST}, L] RewriteCond %{REQUEST_URI}!^/(uploads extras)/ RewriteRule ^/(.*)$ to://${dynamic:%{http_host}}/$1 RewriteRule ^to://([^/])+/(.*) http://$1/$2 [E=SERVER:$1,P,L] RewriteRule.* - [F]
Advanced Webserver Setups for WebGUI a mod_perl handler for serving WebGUI requests Apache::WebGUI library flexible & scalable WebGUI Server
WebGUI without VHosts httpd.conf <Location /webgui-request> SetHandler perl-script PerlHandler Apache::WebGUI::Request </Location> Apache::WebGUI::Request sub handler { 1 my $r = shift; 2 my $configfile = _getconfig($r); 3 my $webguiroot = $r->dir_config( webguiroot ); 4 my $location = $r->location; 5 $ENV{'PATH_INFO'} = $ENV{'REQUEST_URI'}; 6 $ENV{'PATH_INFO'} =~ s/^$location(\/\w*)(\?.*)?$/$1/; 7 print WebGUI::page($webguiRoot, $configfile); 8 return OK; }
Building a Webserver System for WebGUI internet client request WebGUI RProxy / SC Server WebGUI Request Servers Apache::WebGUI filter & mapping System
Apache::WebGUI Library 1
Fully Flexible & Scalable WebGUI Server System internet client WebGUI RProxy / SC Server FS FS FS WebGUI Site Administration System WebGUI Request Servers Database Servers
Questions?
Drinks?