Simple Apache + FastCGI + Django Configuration Guide

Source: Internet
Author: User
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]
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.