This article mainly introduces the simple Apache + FastCGI + Django Configuration Guide, this is also the most popular environment for deploying Django, the most popular web framework in Python. For more information, see use Django on Apache and FastCGI. you need to install and configure Apache, install mod_fastcgi. See Apache and mod_fastcgi documents: http://www.djangoproject.com/r/mod_fastcgi.
After the installation is complete, Apache and Django FastCGI can communicate with each other through httpd. conf (Apache configuration file. You need to do two things:
- Use FastCGIExternalServer to specify the location of FastCGI.
- Use mod_rewrite to specify an appropriate URL for FastCGI.
Location of FastCGI Server
FastCGIExternalServer tells Apache how to find the FastCGI server. According to the FastCGIExternalServer document (http://www.djangoproject.com/r/mod_fastcgi/FastCGIExternalServer/), you can specify the socket or host. The following 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, but the/home/user/public_html/mysite. fcgi file may not exist. It is only an interface used inside the Web server. this URL determines which URL requests will be processed by FastCGI (discussed in the next section ). (More information will be provided 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 certain patterns. To achieve this, use the mod_rewrite module and redirect these URLs to mysite. fcgi (or, as described earlier, use any content specified in FastCGIExternalServer ).
In this example, we tell Apache to use FastCGI to process files not provided 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.fcgi/$1 [QSA,L]