简单的Apache+FastCGI+Django配置指南

yipeiwu_com6年前Python基础

在Apache和FastCGI上使用Django,你需要安装和配置Apache,并且安装mod_fastcgi。 请参见Apache和mod_fastcgi文档: http://www.djangoproject.com/r/mod_fastcgi/ 。

当完成了安装,通过 httpd.conf (Apache的配置文件)来让Apache和Django FastCGI互相通信。 你需要做两件事:

  •     使用 FastCGIExternalServer 指明FastCGI的位置。
  •     使用 mod_rewrite 为FastCGI指定合适的URL。

指定 FastCGI Server 的位置

FastCGIExternalServer 告诉Apache如何找到FastCGI服务器。 按照FastCGIExternalServer 文档( http://www.djangoproject.com/r/mod_fastcgi/FastCGIExternalServer/ ),你可以指明 socket 或者 host 。以下是两个例子:

# 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

在这两个例子中, /home/user/public_html/ 目录必须存在,而 /home/user/public_html/mysite.fcgi 文件不一定存在。 它仅仅是一个Web服务器内部使用的接口,这个URL决定了对于哪些URL的请求会被FastCGI处理(下一部分详细讨论)。 (下一章将会有更多有关于此的介绍)
使用mod_rewrite为FastCGI指定URL

第二步是告诉Apache为符合一定模式的URL使用FastCGI。 为了实现这一点,请使用mod_rewrite 模块,并将这些URL重定向到 mysite.fcgi (或者正如在前文中描述的那样,使用任何在 FastCGIExternalServer 指定的内容)。

在这个例子里面,我们告诉Apache使用FastCGI来处理那些在文件系统上不提供文件

<VirtualHost 12.34.56.78>
 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]
</VirtualHost>


相关文章

pytorch中torch.max和Tensor.view函数用法详解

torch.max() 1. torch.max()简单来说是返回一个tensor中的最大值。 例如: >>> si=torch.randn(4,5) >&g...

Python enumerate函数功能与用法示例

本文实例讲述了Python enumerate函数功能与用法。分享给大家供大家参考,具体如下: eunmerate在英文中是列举、枚举的意思,在python中eunmerate()是一个...

Python格式化压缩后的JS文件的方法

本文实例讲述了Python格式化压缩后的JS文件的方法。分享给大家供大家参考。具体分析如下: 该脚本可以把压缩后的js文件格式上进行些还原,当然不会百分百完美,暂不处理语法问题,只是为了...

Python中GeoJson和bokeh-1的使用讲解

Python中GeoJson和bokeh-1的使用讲解

GeoJson 文档 { "type": "FeatureCollection", "features": [ { "geometry": { "type":...

python二进制文件的转译详解

首先导入所需的包:import struct struct有以下几个主要的函数: # 按照给定的格式(fmt),把数据封装成字符串(实际上是类似于c结构体的字节流) pack(fmt...