php和django在同一个lighttpd服务器上

时间:2014-04-28 19:34:32

标签: php python django lighttpd

我有工作lighttpd + django服务器,但我也想要php例如: www.mydomian.com是django主页,www.mydomian.com/owncloud是owncloud发行版。有可能这样做吗?对我可怕的英语真的很抱歉;)这是我的lighttpd.conf

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
        "mod_rewrite",

)
server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

$SERVER["socket"] == "localhost:443" {
    ssl.engine = "enable"
        ssl.pemfile = "/etc/lighttpd/ssl/server.pem"  
    }
$HTTP["url"] =~ "^/owncloud/data/" {
        url.access-deny = ("")
}

#$SERVER["socket"] == "localhost:8000" {
#server.document-root = "/var/www/"   
# prawa dostępu dla "http"


fastcgi.server += (
    "/projekt.fcgi" => (
        "main" => (
            "host" => "127.0.0.1",
            "port" => 3033,
            #"socket" => "/var/www/projekt.sock",
            "check-local" => "disable",
        )
    )
)
fastcgi.server += (
    "/admin.fcgi" => (
        "admin" => (
            "host" => "127.0.0.1",
            "port" => 3033,
            #"socket" => "/var/www/projekt.sock",
            "check-local" => "disable",
        )
    )
)
alias.url = (
    "/static" => "/var/www/static",
    "/media" => "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/",
)
url.rewrite-once = (
"^(/static.*)$" => "$1",
"^(/Media.*)$" => "$1",
"^(/.*)$" => "/projekt.fcgi$1",
"^(/owncloud.*)$" => "index.php$1",
)
#}

而且这个:

# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" => 
    ((
        "bin-path" => "/usr/bin/php-cgi",
        "socket" => "/var/run/lighttpd/php.socket",
        "max-procs" => 1,
        "bin-environment" => ( 
            "PHP_FCGI_CHILDREN" => "4",
            "PHP_FCGI_MAX_REQUESTS" => "10000"
        ),
        "bin-copy-environment" => (
            "PATH", "SHELL", "USER"
        ),
        "broken-scriptfilename" => "enable"
    ))
)

感谢您的帮助, Sierran

修改

现在工作得很好。但SSL仅适用于服务器IP,而不适用于domian。更新了配置文件:

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
        "mod_rewrite",

)
server.document-root        = "/var/www/"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

#$SERVER["socket"] == ":443" {
#   ssl.engine = "enable"
#        ssl.pemfile = "/etc/lighttpd/ssl/server.pem"  
#   server.name = "mydomian.eu"
#      
#}


$HTTP["url"] =~ "^/owncloud/data/" {
        url.access-deny = ("")
}


$SERVER["socket"] == ":443" {
    ssl.engine = "enable"
    ssl.pemfile = "/etc/lighttpd/ssl/server.pem"
    $HTTP["host"] == "mydomian.eu" {
            ssl.pemfile = "/etc/lighttpd/ssl/mydomian.eu.pem" 
        }
    }

$HTTP["host"] =~ "^(www\.)?mydomian\.eu" {
server.document-root = "/var/www/" 
fastcgi.server += (
    "/projekt.fcgi" => (
        "main" => (
            "host" => "127.0.0.1",
            "port" => 3033,
            #"socket" => "/var/www/projekt.sock",
            "check-local" => "disable",
        )
    )
)

url.rewrite-once = (
"^(/static.*)$" => "$1",
"^(/Media.*)$" => "$1",
"^(.*)$" => "/projekt.fcgi$1",
)
}

alias.url = (
    "/static" => "/var/www/static",
    "/media" => "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/",
)

1 个答案:

答案 0 :(得分:2)

只要您可以在操作系统本身上安装必要的PHP和Python软件包,您运行的服务器渲染软件类型(例如Apache,lighttpd等)并不重要。 (使用任何* nix-server操作系统,如Ubuntu-server / CentOS,这很容易做到。)

虽然我不熟悉lighttpd,但我要考虑的是将owncloud软件映射到子域:

owncloud.mydomain.com

处理子域比/链接URL容易得多。此外,您将避免与/ link冲突,因为您可能希望在django本身(对于其他页面)中创建更多链接。

您需要做的是使用lighttpd软件为网站的不同部分创建特殊用例。例如,您将为:

做出规定

mydomain.com/www.mydomain.com owncloud.mydomain.com

我希望我的逻辑对你有意义。如果您需要更多信息,请对我的帖子发表评论,我们可以对其进行编辑,直到找到正确的答案。