Tuesday, August 10, 2010

Configuring QP and Apache2 to use scgi.

August 11.

We are now getting more familiar with configuring Apache2 and QP. We hope to contribute more documentation so more people will use QP/QPY with Apache2 (if Apache2 is their web server).



Configuring QP for scgi.


QP is actually a server with optional scgi capabilities. Due to its small size, the code runs quickly. There will be an article later why QP should use scgi. Perhaps the main advantage is aesthetic. There is no ugly port number in the url address of the application. Another is that Apache can serve static content quickly.


In the QP configuration section, add an entry for scgi_address.


class SitePublisher (DurusPublisher):
configuration = dict(
durus_address=('localhost', 7003),
http_address=('localhost', 8003), # may be deleted if scgi_address is specified.
as_https_address=('localhost', 9003),
https_address=('localhost', 10003),
scgi_address =('127.0.0.1', 3007) #http_address will be ignored if included.
)



Configuring Apache2 to use scgi

The configuration files for Apache are found in the /etc/apache2 directory. Create a file configuration file proto(touch proto) inside the sites-available subdirectory. Then create a softlink proto inside the sites-enabled subdirectory to point to sites-available/proto. Here is a virtual host template for the proto example which works in my Linux VPS host.
Replace mydomain, with your own domain, say abc-services.

LoadModule scgi_module //mod_scgi.so

AddDefaultCharset utf-8
ServerName www.proto.mydomain
ServerAlias proto.mydomain

# Decomment the following for special html errors pages.
DocumentRoot /var/www/
#ErrorDocument 500 /500.html
#ErrorDocument 404 /404.html

# handle all requests through SCGI
SCGIMount / 127.0.0.1:3007



Issue sudo a2enmod mod_scgi to make Apache use mod_scgi forever. Otherwise add the line before the settings the line
LoadModule scgi_module /usr/lib/apache2/modules/mod_scgi.so

After saving the config file, don't forget to restart apache2!

sudo /etc/init.d/apache2 restart

Accessing the scgi/Apache2 powered web application

Use the url http://wwww.proto.mydomain/ to access the proto example.


Serving Static file


There is still a problem though. The static files are not served by Apache2, i.e., we want proto.mydomain/all.css to work instead of as wanted by the scgi client. proto.mydomain/scgi/all.css. We will worry about this later when we have more than a thousand visitors!For the impatient, one can try the following


Alias /static "/path/to/static/files/dir"

SetHandler None
Options -Indexes +FollowSymLinks
allow from all



Remarks. It is recommended that the python-passfd package be installed. Use sudo easy_install python-passfd.



Acknowledgments: QP mailing list, Support at Rimuhosting for their helpful replies.

Experiment with the settings. And please share the knowledge gained with other Python programming language lovers.

No comments:

Post a Comment