「Lighttpd」の版間の差分
Kusakata.bot (トーク | 投稿記録) (Pkg/AUR テンプレートの更新) |
Kusakata.bot2 (トーク | 投稿記録) (Pkg/AUR テンプレートの更新) |
||
| (2人の利用者による、間の4版が非表示) | |||
| 1行目: | 1行目: | ||
| + | {{Lowercase title}} |
||
[[Category:ウェブサーバー]] |
[[Category:ウェブサーバー]] |
||
[[cs:Lighttpd]] |
[[cs:Lighttpd]] |
||
| 7行目: | 8行目: | ||
[[zh-hans:Lighttpd]] |
[[zh-hans:Lighttpd]] |
||
[[zh-hant:Lighttpd]] |
[[zh-hant:Lighttpd]] |
||
| − | [https://www.lighttpd.net/ |
+ | [https://www.lighttpd.net/ lighttpd] は高速性の重視される環境に最適化された、安全・高速で標準に準拠し、とても柔軟な[[Wikipedia:ja:Webサーバ|ウェブサーバー]]です。他のウェブサーバーと比べてメモリ使用量や CPU 負担が少ないのが特徴です。高度な機能セット ([[Wikipedia:ja:FastCGI|FastCGI]], [[Wikipedia:ja:Common Gateway Interface|CGI]], 認証, 圧縮出力, URL の書き換えなど) により、lighttpd は負担が気になるサーバーにうってつけのウェブサーバーソフトウェアとして君臨します。 |
==インストール== |
==インストール== |
||
| 33行目: | 34行目: | ||
==== ログ出力 ==== |
==== ログ出力 ==== |
||
| − | + | lighttpd はエラー・アクセスログをファイルに書き出すことができます。ログオプションを有効にするには {{ic|/etc/lighttpd/lighttpd.conf}} を以下のように編集: |
|
server.modules += ( |
server.modules += ( |
||
"mod_access", |
"mod_access", |
||
| 65行目: | 66行目: | ||
===== Let's Encrypt ===== |
===== Let's Encrypt ===== |
||
| − | [[Let's Encrypt]] によって署名された証明書を使うこともできます。手動で証明書を作成した後、生成された {{ic|privkey.pem}} と {{ic| |
+ | [[Let's Encrypt]] によって署名された証明書を使うこともできます。手動で証明書を作成した後、生成された {{ic|privkey.pem}} と {{ic|fullchain.pem}} をひとつのファイルに結合してください: |
| − | # cat /etc/letsencrypt/live/''domain''/{privkey.pem, |
+ | # cat /etc/letsencrypt/live/''domain''/{privkey.pem,fullchain.pem} > /etc/letsencrypt/live/''domain''/combined.pem |
{{ic|/etc/lighttpd/lighttpd.conf}} を編集して以下の行を追加します: |
{{ic|/etc/lighttpd/lighttpd.conf}} を編集して以下の行を追加します: |
||
| 74行目: | 75行目: | ||
ssl.engine = "enable" |
ssl.engine = "enable" |
||
ssl.pemfile = "/etc/letsencrypt/live/''domain''/combined.pem" |
ssl.pemfile = "/etc/letsencrypt/live/''domain''/combined.pem" |
||
| − | ssl.ca-file = "/etc/letsencrypt/live/''domain''/ |
+ | ssl.ca-file = "/etc/letsencrypt/live/''domain''/fullchain.pem" |
} |
} |
||
| + | |||
| + | curl で接続したときに "empty reply from server" と返される場合、上記の設定に以下を追加してください: |
||
| + | ssl.openssl.ssl-conf-cmd = ("Protocol" => "-ALL, TLSv1.2") |
||
| + | また、上記の設定で Firefox を使って HTTPS でサイトをロードできない場合も解決することがあります。 |
||
==== ディレクトリのパスワード保護 ==== |
==== ディレクトリのパスワード保護 ==== |
||
| − | {{Pkg|libmariadbclient}} をインストールする必要があります。lighttpd の passwd ファイルはシステムがユーザー認証に使用する {{ic|/etc/passwd}} と同じです。以下のように簡単にエントリを作成することができます: |
+ | {{Pkg|libmariadbclient}}{{Broken package link|置換パッケージ: {{Pkg|mariadb-libs}}}} をインストールする必要があります。lighttpd の passwd ファイルはシステムがユーザー認証に使用する {{ic|/etc/passwd}} と同じです。以下のように簡単にエントリを作成することができます: |
$ user=foo |
$ user=foo |
||
$ password=b@R102 |
$ password=b@R102 |
||
$ realm='Password Required' |
$ realm='Password Required' |
||
| − | $ hash=`echo -n "$user:$realm:$ |
+ | $ hash=`echo -n "$user:$realm:$password" | md5sum | cut -b -32` |
# echo "$user:$realm:$hash" >> /etc/lighttpd/lighttpd.user |
# echo "$user:$realm:$hash" >> /etc/lighttpd/lighttpd.user |
||
| 251行目: | 256行目: | ||
FastCGI をインストール・設定してください (上の [[#FastCGI]] を参照)。 |
FastCGI をインストール・設定してください (上の [[#FastCGI]] を参照)。 |
||
| − | {{ |
+ | {{Pkg|python2-flup}}{{Broken package link|パッケージが存在しません}} をインストールして以下のように設定: |
fastcgi.server = ( |
fastcgi.server = ( |
||
".py" => |
".py" => |
||
| 345行目: | 350行目: | ||
以下を {{ic|/etc/lighttpd/lighttpd.conf}} に追加: |
以下を {{ic|/etc/lighttpd/lighttpd.conf}} に追加: |
||
include "conf.d/compress.conf" |
include "conf.d/compress.conf" |
||
| + | 圧縮したいコンテンツのタイプを選択することもできます。{{ic|/etc/lighttpd/conf.d/compress.conf}} の {{ic|compress.filetype}} パラメータを編集してください: |
||
| + | compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml") |
||
== 参照 == |
== 参照 == |
||
2020年12月31日 (木) 14:45時点における最新版
lighttpd は高速性の重視される環境に最適化された、安全・高速で標準に準拠し、とても柔軟なウェブサーバーです。他のウェブサーバーと比べてメモリ使用量や CPU 負担が少ないのが特徴です。高度な機能セット (FastCGI, CGI, 認証, 圧縮出力, URL の書き換えなど) により、lighttpd は負担が気になるサーバーにうってつけのウェブサーバーソフトウェアとして君臨します。
目次
インストール
lighttpd パッケージをインストールしてください。
設定
基本設定
lighttpd の設定ファイルは /etc/lighttpd/lighttpd.conf です。デフォルトではテストページが表示されるようになっています。
lighttpd.conf に問題が存在しないか次のコマンドを使うことで確認できます、これによって設定の誤りを早期発見することが可能です:
$ lighttpd -t -f /etc/lighttpd/lighttpd.conf
デフォルトの設定ファイルでは /srv/http/ をウェブ上に公開するドキュメントのディレクトリとして指定しています。
インストールが正しく行われたかテストするには:
# echo 'TestMe!' >> /srv/http/index.html # chmod 755 /srv/http/index.html
lighttpd.service を起動・有効化してサーバーを起動してください。
ブラウザで localhost を開いて見てください、テストページが表示されるはずです。
設定ファイルのサンプルは /usr/share/doc/lighttpd/ にあります。
ログ出力
lighttpd はエラー・アクセスログをファイルに書き出すことができます。ログオプションを有効にするには /etc/lighttpd/lighttpd.conf を以下のように編集:
server.modules += ( "mod_access", "mod_accesslog", ) server.errorlog = "/var/log/lighttpd/error.log" accesslog.filename = "/var/log/lighttpd/access.log"
SSL による HTTPS の有効化
自己署名証明書
自己署名 SSL 証明書は以下のように作成できます (openssl のインストールが必要です):
# mkdir /etc/lighttpd/certs # openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -sha256 -keyout /etc/lighttpd/certs/server.pem -out /etc/lighttpd/certs/server.pem # chmod 600 /etc/lighttpd/certs/server.pem
/etc/lighttpd/lighttpd.conf を編集して以下の行を追加すれば https が有効になります:
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/certs/server.pem"
}
Let's Encrypt
Let's Encrypt によって署名された証明書を使うこともできます。手動で証明書を作成した後、生成された privkey.pem と fullchain.pem をひとつのファイルに結合してください:
# cat /etc/letsencrypt/live/domain/{privkey.pem,fullchain.pem} > /etc/letsencrypt/live/domain/combined.pem
/etc/lighttpd/lighttpd.conf を編集して以下の行を追加します:
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/letsencrypt/live/domain/combined.pem"
ssl.ca-file = "/etc/letsencrypt/live/domain/fullchain.pem"
}
curl で接続したときに "empty reply from server" と返される場合、上記の設定に以下を追加してください:
ssl.openssl.ssl-conf-cmd = ("Protocol" => "-ALL, TLSv1.2")
また、上記の設定で Firefox を使って HTTPS でサイトをロードできない場合も解決することがあります。
ディレクトリのパスワード保護
libmariadbclient[リンク切れ: 置換パッケージ: mariadb-libs] をインストールする必要があります。lighttpd の passwd ファイルはシステムがユーザー認証に使用する /etc/passwd と同じです。以下のように簡単にエントリを作成することができます:
$ user=foo $ password=b@R102 $ realm='Password Required' $ hash=`echo -n "$user:$realm:$password" | md5sum | cut -b -32` # echo "$user:$realm:$hash" >> /etc/lighttpd/lighttpd.user
/etc/lighttpd/lighttpd.conf を編集して以下の行を追加することでディレクトリの保護が有効になります:
server.modules = (
"mod_auth",
)
auth.debug = 2
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/lighttpd/lighttpd.user"
# note this entry is relative to the server.document-root
auth.require = ( "/secret" =>
(
"method" => "basic",
"realm" => "Password Required",
"require" => "user=foo"
)
)
CGI
Lighttpd では、特に設定をしなくても、CGI モジュールを有効にするだけで CGI スクリプトが動作します。使用するプログラミング言語のインタプリタがインストールされているか確認してください (例えば python なら python をインストールします)。
/etc/lighttpd/conf.d/cgi.conf ファイルを作成して以下の内容を追加します:
server.modules += ( "mod_cgi" )
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl",
".rb" => "/usr/bin/ruby",
".erb" => "/usr/bin/eruby",
".py" => "/usr/bin/python",
".php" => "/usr/bin/php-cgi" )
index-file.names += ( "index.pl", "default.pl",
"index.rb", "default.rb",
"index.erb", "default.erb",
"index.py", "default.py",
"index.php", "default.php" )
PHP スクリプトの場合、以下を /etc/php/php.ini に設定する必要があります:
cgi.fix_pathinfo = 1
Lighttpd の設定ファイルを /etc/lighttpd/lighttpd.conf に以下を追加してください:
include "conf.d/cgi.conf"
FastCGI
fcgi をインストールしてください。それで lighttpd に fcgi サポートが追加されます。fcgi サポートを追加するだけなら設定はそれだけです。Ruby on Rails, PHP, Python などを使いたい場合は以下を読んで下さい。
まず /usr/share/doc/lighttpd/config/conf.d/fastcgi.conf から /etc/lighttpd/conf.d にサンプル設定ファイルをコピーします。
以下を設定ファイル /etc/lighttpd/conf.d/fastcgi.conf に追加する必要があります:
server.modules += ( "mod_fastcgi" )
#server.indexfiles += ( "dispatch.fcgi" ) #this is deprecated
index-file.names += ( "dispatch.fcgi" ) #dispatch.fcgi if rails specified
server.error-handler-404 = "/dispatch.fcgi" #too
fastcgi.server = (
".fcgi" => (
"localhost" => (
"socket" => "/run/lighttpd/rails-fastcgi.sock",
"bin-path" => "/path/to/rails/application/public/dispatch.fcgi"
)
)
)
そして /etc/lighttpd/lighttpd.conf に以下を記述してください:
include "conf.d/fastcgi.conf"
PHP
php-cgi を使う
php と php-cgi をインストールします (PHP や LAMP を参照)。
php-cgi が動作するかは php-cgi --version で確認:
PHP 5.4.3 (cgi-fcgi) (built: May 8 2012 17:10:17) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
以上のように出力されたら php は正しくインストールされています。
新しい設定ファイルを作成:
/etc/lighttpd/conf.d/fastcgi.conf
# Make sure to install php and php-cgi. See:
# https://wiki.archlinux.org/index.php/Fastcgi_and_lighttpd#PHP
server.modules += ("mod_fastcgi")
# FCGI server
# ===========
#
# Configure a FastCGI server which handles PHP requests.
#
index-file.names += ("index.php")
fastcgi.server = (
# Load-balance requests for this path...
".php" => (
# ... among the following FastCGI servers. The string naming each
# server is just a label used in the logs to identify the server.
"localhost" => (
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php-fastcgi.sock",
# breaks SCRIPT_FILENAME in a way that PHP can extract PATH_INFO
# from it
"broken-scriptfilename" => "enable",
# Launch (max-procs + (max-procs * PHP_FCGI_CHILDREN)) procs, where
# max-procs are "watchers" and the rest are "workers". See:
# https://redmine.lighttpd.net/projects/1/wiki/frequentlyaskedquestions#How-many-php-CGI-processes-will-lighttpd-spawn
"max-procs" => 4, # default value
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "1" # default value
)
)
)
)
lighttpd が新しい設定ファイルを使うように設定:
/etc/lighttpd/lighttpd.conf
include "conf.d/fastcgi.conf"
lighttpd をリロード:
# systemctl reload lighttpd
php-fpm を使う
最近の lighttpd のリリースでは適応型のプロセス生成はなくなっています。PHP プロセスの動的な管理がしたい場合は、php-fpm をインストールしてください。そして php-fpm.service を起動・有効化してください。
/etc/lighttpd/conf.d/fastcgi.conf に以下を追加:
server.modules += ( "mod_fastcgi" )
index-file.names += ( "index.php" )
fastcgi.server = (
".php" => (
"localhost" => (
"socket" => "/run/php-fpm/php-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
Python FastCGI
FastCGI をインストール・設定してください (上の #FastCGI を参照)。
python2-flup[リンク切れ: パッケージが存在しません] をインストールして以下のように設定:
fastcgi.server = (
".py" =>
(
"python-fcgi" =>
(
"socket" => "/run/lighttpd/fastcgi.python.socket",
"bin-path" => "test.py",
"check-local" => "disable",
"max-procs" => 1,
)
)
)
test.py をサーバーのルートに置いて下さい (忘れずに chmod +x で実行権限を与えます)。
#!/usr/bin/env python2
def myapp(environ, start_response):
print 'got request: %s' % environ
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!']
if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()
詳しくは こちらの投稿 を参照。
Server Name Indication
lighttpd で SNI を使用するには、ssl.pemfile 設定ディレクティブを host 条件文の中に追加してください。デフォルトの ssl.pemfile が必要です。
$HTTP["host"] == "www.example.org" {
ssl.pemfile = "/etc/lighttpd/certs/www.example.org.pem"
}
$HTTP["host"] == "mail.example.org" {
ssl.pemfile = "/etc/lighttpd/certs/mail.example.org.pem"
}
HTTP のリクエストを HTTPS にリダイレクト
/etc/lighttpd/lighttpd.conf の server.modules 行に "mod_redirect" を追加してください:
server.modules += ( "mod_redirect" )
$SERVER["socket"] == ":80" {
$HTTP["host"] =~ "example.org" {
url.redirect = ( "^/(.*)" => "https://example.org/$1" )
server.name = "example.org"
}
}
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/certs/server.pem"
server.document-root = "..."
}
全てのホストをセキュアな URL にリダイレクトするには上の socket 80 の設定のところに以下を記述します:
$SERVER["socket"] == ":80" {
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
}
サイトの一部だけリダイレクトするには (例: secure または phpmyadmin):
$SERVER["socket"] == ":80" {
$HTTP["url"] =~ "^/secure" {
url.redirect = ( "^/(.*)" => "https://example.com/$1" )
}
}
圧縮出力
/etc/lighttpd/lighttpd.conf に以下を追加:
var.cache_dir = "/var/cache/lighttpd"
圧縮ファイル用にディレクトリを作成:
# mkdir /var/cache/lighttpd/compress # chown http:http /var/cache/lighttpd/compress
サンプル設定ファイルをコピー:
# mkdir /etc/lighttpd/conf.d # cp /usr/share/doc/lighttpd/config/conf.d/compress.conf /etc/lighttpd/conf.d/
以下を /etc/lighttpd/lighttpd.conf に追加:
include "conf.d/compress.conf"
圧縮したいコンテンツのタイプを選択することもできます。/etc/lighttpd/conf.d/compress.conf の compress.filetype パラメータを編集してください:
compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml")