在同一lighttpd服务器上运行php和django

2 投票
1 回答
507 浏览
提问于 2025-04-18 04:38

我有一个正在运行的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上工作,而在域名上不行。更新后的配置文件:

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 个回答

2

其实你用什么样的服务器软件并不重要,比如说Apache、lighttpd等等,只要你能在操作系统上安装好需要的PHP和Python包就行了。对于任何一种类Unix的服务器操作系统,比如Ubuntu-server或CentOS,这个过程都非常简单。

虽然我对lighttpd不太熟悉,但我建议你可以把owncloud软件设置成一个子域名:

owncloud.mydomain.com

使用子域名比用/link这样的链接要简单得多。而且,这样可以避免和/link产生冲突,因为你可能还想在django里创建更多的链接(用于其他页面)。

你需要做的是为你网站的不同部分创建一些特殊的使用案例,利用你的lighttpd软件。比如,你可以设置:

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

希望我的想法对你有帮助。如果你需要更多信息,可以在我的帖子下评论,我们可以一起修改,直到找到正确的答案。

撰写回答