Lighttpd:启用 IPv6 支持
Lighttpd 开箱即用地支持 IPv6 和 IPv4 协议。您需要使用 IPv6 支持编译 lighttpd。server.use-ipv6 选项绑定到 IPv6 套接字。您需要使用以下语法绑定到 IPv6 和 IPv4。
首先,查看编译时功能(查明是否启用了 IPv6),输入:
# lighttpd -V
示例输出:
Build-Date: Sep 30 2008 06:18:08 Event Handlers: + select (generic) + poll (Unix) + rt-signals (Linux 2.4+) + epoll (Linux 2.6) - /dev/poll (Solaris) - kqueue (FreeBSD) Network handler: + sendfile Features: + IPv6 support + zlib support + bzip2 support + crypt support + SSL Support + PCRE support - mySQL support - LDAP support - memcached support - FAM support - LUA support - xml support - SQLite support - GDBM support
您必须看到 + IPv6 支持已启用。如果没有,请重新编译 lighttpd 以支持 IPv6。编译后打开 lighttpd.conf 文件:
# vi lighttpd.conf
要同时启用 IPV6 和 IPV4,请输入:
server.use-ipv6 = "enable" server.port = 80 $SERVER["socket"] == "0.0.0.0:80" { # add your stuff # }
保存并关闭文件。重新启动lighttpd:
# service lighttpd restart
上述配置仅在您想要使用所有可用的 IPv4 和 IPv6 地址时才有用。以下配置将 IPv4 绑定到 202.54.1.10 并将 IPv6 绑定到地址:
打开 lighttpd.conf 设置主服务器 IP 地址,如下所示:
server.port = 80 server.bind = "202.54.1.10"
下面添加 IPv6 配置如下:
$SERVER["socket"] == "[2001:470:1f04:55a::2]:80" { # ... # your rest of config for ipv6 host # ... }
下面是启用了 IPv4 和 IPv6 双栈的示例配置文件:
server.modules = ( "mod_redirect", "mod_alias", "mod_rewrite", "mod_expire", "mod_access", "mod_auth", "mod_status", "mod_fastcgi", "mod_accesslog", "mod_compress" ) server.errorlog = "/var/log/lighttpd/error.log" accesslog.filename = "/var/log/lighttpd/access.log" index-file.names = ( "index.php", "index.html", "index.htm", "default.htm" ) server.tag = "lighttpd" # FastCGI php5 fastcgi.map-extensions = ( ".html" => ".php" ) fastcgi.server = ( ".php" => (( "bin-path" => "/usr/bin/php-cgi", "socket" => "/tmp/php-cgi.socket", "max-procs" => 4, "idle-timeout" => 30, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "10", "PHP_FCGI_MAX_REQUESTS" => "20000" ), "bin-copy-environment" => ( "PATH", "SHELL", "USER" ), "broken-scriptfilename" => "enable" )) ) include "mimetype.conf" server.document-root = "/home/lighttpd/example.com/http" server.pid-file = "/var/run/lighttpd.pid" server.username = "lighttpd" server.groupname = "lighttpd" # Turn on IPv4 config server.port = 80 server.bind = "202.54.1.10" server.error-handler-404 = "/index.php?error=404" ### IPv6 Config ### # Note only log file name changed $SERVER["socket"] == "[2607:f0d0:1002:11::5]:80" { accesslog.filename = "/var/log/lighttpd/ipv6.access.log" server.document-root = "/home/lighttpd/example.com/http" server.error-handler-404 = "/index.php?error=404" }