かぴぶろぐ

またかぴったかと思った・・・(´A`;)

lighttpd phpとpythonとかのconf設定サンプル

pylons and webpy and php
カテゴリ[ Linux Unix ]

まずlighttpd.confを分けた。ちょっとapacheぽく。

> ls
lighttpd-auth.conf  lighttpd-mime.conf  lighttpd-vhost.conf  lighttpd.conf

lighttpd.conf

server.port = 80
server.document-root        = "/opt/www/htdocs/"

server.modules              = (
                               "mod_rewrite",
                               "mod_access",
                               "mod_auth",
                               "mod_accesslog",
                               "mod_fastcgi",
                               "mod_scgi",
                               "mod_proxy",
                               )


### Log ###
server.errorlog             = "/opt/logs/lighttpd_error.log"
accesslog.filename          = "/opt/logs/lighttpd_access.log"


### include
include "lighttpd-mime.conf"
include "lighttpd-vhost.conf"
#include "lighttpd-auth.conf" #Basic認証するとき外す

lighttpd-mime.conf

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )

mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jar"          =>      "application/x-java-archive",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  # default mime type
  ""              =>      "application/octet-stream",
 )

url.access-deny             = ( "~", ".inc" )

$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

lighttpd-auth.conf

### Basic Auth ###
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/opt/apps/lighttpd-1.4/etc/.htpasswd"
auth.require = ( "/" =>
                 (
                   "method"  => "basic",
                   "realm"   => "Secret Zone",
                   "require" => "valid-user"
                 )
)

lighttpd-vhost.conf

### host centos ###

$HTTP["host"] == "centos" {
    server.document-root        = "/opt/www/htdocs"
}


### host pylons ###

$HTTP["host"] == "pylons" {
    server.document-root        = "/opt/www/pylons_dev/helloworld"
    server.name = "pylons"
    scgi.server = ("" =>
        (
            (
                "host" => "127.0.0.1",
                "port" => 5000,
                "min-procs" => 1,
                "max-procs" => 2,
                "check-local" => "disable"
            )
        )

    )
   
   url.rewrite-once = (
     "^/favicon.ico$" => "/public/favicon.ico",
     "^/images/(.*)$" => "/public/images/$1",
     "^/css/(.*)$" => "/public/css/$1",
     "^/scripts/(.*)$" => "/public/scripts/$1",
     "^(/.*)$" => "/$1"
   )

}


### host php_and_python(webpy) ###

$HTTP["host"] == "php_and_python" {

    server.document-root = "/opt/www/php_dev"

    fastcgi.server = (

        ".php" =>
            (
                (
                    "socket" => "/tmp/php.socket",
                    "bin-path" => "/usr/bin/php-cgi",
                    "bin-environment" =>
                        (
                            "PHP_FCGI_CHILDREN" => "16",
                            "PHP_FCGI_MAX_REQUESTS" => "10000"
                        ),
                   "min-procs" => 1,
                   "max-procs" => 1,
                   "idle-timeout" => 20
                )
            ),
       
        "/main.py" =>
            (
                (
                    "socket" => "/tmp/fastcgi.socket",
                    "bin-path" => "/opt/www/webpy_dev/helloworld/main.py",
                    "max-procs" => 1,
                    "check-local" => "disable"
                )
            )
       
        )
   
   
   
    url.rewrite-once = (
        "^/favicon.ico$" => "/favicon.ico",
        "^/static/(.*)$" => "/static/$1"
    )

}

 

あくまで「サンプル」です。

個々ではちゃんと動かしましたが、全部一まとめとか動くかは確認してません・・。

pythonとphp環境って今後もありえそうなのでメモ。個人的にはapacheよりlighttpdは好きだなぁ。
エラーが分かり辛いけど。。

参考URL

http://kapi.jp/kapi_blog/233

2009年05月19日

関連カテゴリ Python Linux Unix PHP Pylons

この記事のコメント

この記事にコメントする