Using Django on Apache and fastcgi, you need to install and configure Apache, and install mod_fastcgi. See Apache and mod_fastcgi Documentation: http://www.djangoproject.com/r/mod_fastcgi/.
When the installation is complete, Apache and Django fastcgi communicate with each other via httpd.conf (Apache configuration file). You need to do two things:
- Use Fastcgiexternalserver to indicate the location of the fastcgi.
- Use Mod_rewrite to specify the appropriate URL for fastcgi.
Specify the location of the FastCGI Server
Fastcgiexternalserver tells Apache how to find the FASTCGI server. You can specify the socket or host according to the Fastcgiexternalserver document (http://www.djangoproject.com/r/mod_fastcgi/FastCGIExternalServer/). Here are two examples:
# Connect to FastCGI via a socket/named pipe:fastcgiexternalserver/home/user/public_html/mysite.fcgi-socket/home/user /mysite.sock# Connect to FastCGI via a TCP host/port:fastcgiexternalserver/home/user/public_html/mysite.fcgi-host 127.0.0.1:3033
In these two examples, the/home/user/public_html/directory must exist, and the/home/user/public_html/mysite.fcgi file does not necessarily exist. It is simply an interface used inside a Web server that determines which URLs are fastcgi processed (discussed in detail in the next section). (There will be more on this in the next chapter)
Use mod_rewrite to specify a URL for fastcgi
The second step is to tell Apache to use fastcgi for URLs that conform to a certain pattern. To do this, use the Mod_rewrite module and redirect the URLs to mysite.fcgi (or, as described in the previous article, use any content specified in Fastcgiexternalserver).
In this example, we tell Apache to use fastcgi to handle files that are not available on the file system.
ServerName example.com documentroot/home/user/public_html Alias/media/home/user/python/django/contrib/admin/media Rewriteengine on Rewriterule ^/(media.*) $/$1 [qsa,l] Rewritecond%{request_filename}!-f rewriterule ^/(. *) $/MYSITE.FCG i/$1 [Qsa,l]