這篇文章主要介紹了在Lighttpd服務器中運行Django應用的方法,本文所采用的是最流行的FastCGI模塊,包括同時運行多個Django應用的方法,需要的朋友可以參考下
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主機。
新聞熱點
疑難解答