简单的Apache+FastCGI+Django配置指南
作者:goldensun 时间:2021-01-27 10:09:16
在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>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python str()如何将参数转换为字符串类型
利用Python实现绘制论文中的曲线图
![](https://img.aspxhome.com/file/2023/9/78489_0s.png)
python命令行参数解析OptionParser类用法实例
![](https://img.aspxhome.com/file/2023/6/70736_0s.gif)
Reflow
php下pdo的mysql事务处理用法实例
JavaScript动态调整图片尺寸
ASP中的面向对象类
几款优秀的中文字体设计
![](https://img.aspxhome.com/file/UploadPic/20083/24/2008324173030354s.jpg)
Python基于回溯法子集树模板解决野人与传教士问题示例
![](https://img.aspxhome.com/file/2023/8/60948_0s.jpg)
如何使用postman(新手入门)
![](https://img.aspxhome.com/file/2023/6/58166_0s.jpg)
pycharm设置python文件模板信息过程图解
![](https://img.aspxhome.com/file/2023/0/81620_0s.png)
泛泛而谈界面中的斑马纹设计
![](https://img.aspxhome.com/file/UploadPic/20107/15/bm-001-76s.jpg)
asp制作验证码的方法
多级联动下拉选择框,动态获取下一级
Python利用cv2动态绘制圆和矩形的示例详解
python 合并表格详解
网页特效文字之—沙粒字
![](https://img.aspxhome.com/file/UploadPic/20072/2007231168817s.jpg)
Go语言编程中对文件读写的基本方法整理
matplotlib共享坐标轴的实现(X或Y坐标轴)
![](https://img.aspxhome.com/file/2023/5/83805_0s.png)