|
|||||||
1. Introduction
2. Installing Karrigell 3. The Web server 4. Working with Apache or Xitami 4.1 Apache 4.2 Xitami 5. Programming 6. Debugging 7. Python scripts 8. Karrigell Services 9. Python Inside HTML 10. HTML Inside Python 11. HTMLTags - generate HTML in Python 12. Including documents 13. Sessions 14. Authentication 15. Internationalization |
4. Karrigell with Apache or XitamiAlthough Karrigell can work stand-alone with the integrated web server, you may want to use it with an external server. Apache is the most widespread server in the world, it has excellent performance and stability, it can work on secure mode (SSL), offers log services, etc.4.1 Apache4.1.1 IntroductionTo use Karrigell in Apache you'll need to download and install the following: I recommend you install the latest, stable version of each of the above. Apache will be used as a proxy between the client and the built-in server, so you have to configure Apache so that it sends the requests to the built-in server. Suppose you start Apache on port 80 and the built-in server on port 8081 I copy most of this section from Remi Delon's CherryPy documentation : http://www.cherrypy.org/wiki/BehindApache For Apache, all you need to do now is add a few lines to Apache's config file
In the Dynamic Shared Object (DSO) section, uncomment the lines LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule rewrite_module modules/mod_rewrite.soSomewhere else in the main server configuration section, add the following lines to enable the proxy mode : ProxyRequests On <Proxy *> Order allow,deny Deny from none Allow from all </Proxy> To ask Apache to send the requests to the built-in server, use mod_rewrite. This module parses the original url and changes it according to regular expressions. Here the lines to add are : RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !autostart\.cgi$ RewriteRule ^(.*) http://localhost:8081$1 [P] ErrorDocument 502 /cgi-bin/autostart.cgiThe main functionality is provided by the RewriteRule : it tells Apache to rewrite all the urls to an absolute url corresponding to the built-in server running on port 8081 and use the proxy mode to pass the request If the built-in server is not running, an HTTP error 502 is returned ; the last
line tells Apache to call the script autoscript.cgi is a short script, looking like this on Linux/Unix : #!/usr/local/bin/python print "Content-type: text/html\r\n" print """<html><head><META HTTP-EQUIV="Refresh" CONTENT="10; URL=/"></head><body>Restarting site ...<a href="/">click here<a></body></html>""" import os import sys os.system(sys.executable + \ ' /home/quentel/karrigell/Karrigell-2.2/Karrigell.py -P 8081 -S ' +\ '/home/quentel/karrigell/Karrigell-2.2/Karrigell.ini &') All you have to adapt is the location of python on the first line, and the
path to Start the built-in web server on port 8081 and start Apache. This should be
enough to get it going. Depending on what For security reasons, on Linux Karrigell should be started on a port above 1024 and not as root 4.1.2 Virtual HostsVirtual hosts can be used with Apache to serve different hosts on the same machine with the same server. Since version 2.2, Karrigell has support for virtual hosts, so that you can serve all the virtual hosts with the same instance of the built-in serverIf you have configured
NameVirtualHost 127.0.0.1:80 <VirtualHost 127.0.0.1:80> ServerName karrigell # for use with Karrigell RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !autostart\.cgi$ RewriteRule ^(.*) http://karrigell:8081$1 [P] ErrorDocument 502 /cgi-bin/autostart.cgi </VirtualHost> Of course you change the address and port in <Virtual Host> to the appropriate values 4.2 XitamiXitami is a lightweight and fast web server, available for free. Download the latest version and follow the installation instructionsLaunch the server, then open a console window, go to the Karrigell directory and enter
Xitami and Karrigell are interfaced through the "Long Running Web Process", avoiding the overhead of CGI You can replace |