在Lighttpd服务器中运行Django应用的方法

yipeiwu_com5年前服务器

lighttpd (http://www.djangoproject.com/r/lighttpd/) 是一个轻量级的Web服务器,通常被用来提供静态页面的访问。 它天生支持FastCGI,因此除非你的站点需要一些Apache特有的特性,否则,lighttpd对于静态和动态页面来说都是理想的选择。

确保 mod_fastcgi 在模块列表中,它需要出现在 mod_rewrite 和 mod_access ,但是要在 mod_accesslog 之前。

将下面的内容添加到你的lighttpd的配置文件中:

server.document-root = "/home/user/public_html"
fastcgi.server = (
 "/mysite.fcgi" => (
  "main" => (
   # Use host / port instead of socket for TCP fastcgi
   # "host" => "127.0.0.1",
   # "port" => 3033,
   "socket" => "/home/user/mysite.sock",
   "check-local" => "disable",
  )
 ),
)
alias.url = (
 "/media/" => "/home/user/django/contrib/admin/media/",
)

url.rewrite-once = (
 "^(/media.*)$" => "$1",
 "^/favicon\.ico$" => "/media/favicon.ico",
 "^(/.*)$" => "/mysite.fcgi$1",
)

在一个lighttpd进程中运行多个Django站点

lighttpd允许你使用条件配置来为每个站点分别提供设置。 为了支持FastCGI的多站点,只需要在FastCGI的配置文件中,为每个站点分别建立条件配置项:

# If the hostname is 'www.example1.com'...
$HTTP["host"] == "www.example1.com" {
 server.document-root = "/foo/site1"
 fastcgi.server = (
  ...
 )
 ...
}

# If the hostname is 'www.example2.com'...
$HTTP["host"] == "www.example2.com" {
 server.document-root = "/foo/site2"
 fastcgi.server = (
  ...
 )
 ...
}

你也可以通过 fastcgi.server 中指定多个入口,在同一个站点上实现多个Django安装。 请为每一个安装指定一个FastCGI主机。

 

相关文章

利用django+wechat-python-sdk 创建微信服务器接入的方法

利用django+wechat-python-sdk 创建微信服务器接入的方法

1、版本说明 :python 2.7.10, Django (1.6.11.6),centos7 2、步骤说明: A、django 建立项目 django-admin.py star...

Python写的一个简单DNS服务器实例

因为突然有个邪恶的想法,想在自己的Android平板上面搭建一个DNS服务器,因为平板上之前安装过SL4A和Python的解释器,也想继续学学Python因此,就打算用Python实现了...

python下paramiko模块实现ssh连接登录Linux服务器

本文实例讲述了python下paramiko模块实现ssh连接登录Linux服务器的方法。分享给大家供大家参考。具体分析如下: python下有个paramiko模块,这个模块可以实现s...

python操作ssh实现服务器日志下载的方法

本文实例讲述了python操作ssh实现服务器日志下载的方法。分享给大家供大家参考。具体实现方法如下: #coding:utf-8 """ ssh操作例子 实现了服务器日志下载...

python服务器与android客户端socket通信实例

本文实例讲述了python服务器与android客户端socket通信的方法。分享给大家供大家参考。具体实现方法如下: 首先,服务器端使用python完成,下面为python代码: 复制...