Revision [2373]
Last edited on 2009-07-08 19:15:26 by WikiAdminAdditions:
===Rewrite===
Interesting pass through example. This also demonstrated how different lighttpd's rewrite is than apache's
url.rewrite-once = (
"^/images/.*$" => "$0",
"^/dispatch.php.*$" => "$0",
"^/sitemap.xml" => "$0",
"^/([^/]+)/([^/]+)/([^/]+)/?$" => "/dispatch.php?arg1=$1&arg2=$2&arg3=$3",
"^/([^/]+)/([^/]+)/?$" => "/dispatch.php?arg1=$1&arg2=$2",
"^/([^/]+)/?$" => "/dispatch.php?arg1=$1"
)
Interesting pass through example. This also demonstrated how different lighttpd's rewrite is than apache's
url.rewrite-once = (
"^/images/.*$" => "$0",
"^/dispatch.php.*$" => "$0",
"^/sitemap.xml" => "$0",
"^/([^/]+)/([^/]+)/([^/]+)/?$" => "/dispatch.php?arg1=$1&arg2=$2&arg3=$3",
"^/([^/]+)/([^/]+)/?$" => "/dispatch.php?arg1=$1&arg2=$2",
"^/([^/]+)/?$" => "/dispatch.php?arg1=$1"
)
Revision [2301]
Edited on 2009-05-06 08:56:39 by WikiAdminAdditions:
$HTTP["host"] =~ "www\.foobar\.com" {
# proxy everything except images
$HTTP["url"] !~ "^/images" {
# If no file extension is needed, put "" as the first argument
proxy.server = ( "" =>
( (
"host" => "127.0.0.1",
"port" => 18080
) )
)
}
server.document-root = "/usr/local/jira/atlassian-jira"
accesslog.filename = "/var/log/lighttpd/jira.log"
# proxy everything except images
$HTTP["url"] !~ "^/images" {
# If no file extension is needed, put "" as the first argument
proxy.server = ( "" =>
( (
"host" => "127.0.0.1",
"port" => 18080
) )
)
}
server.document-root = "/usr/local/jira/atlassian-jira"
accesslog.filename = "/var/log/lighttpd/jira.log"
Deletions:
Revision [2232]
Edited on 2009-02-25 07:15:30 by WikiAdminAdditions:
===Lighttpd init script===
%%(bash)
#!/bin/sh
#
# lighttpd Startup script for the lighttpd server
#
# chkconfig: - 85 15
# description: Lightning fast webserver with light system requirements
#
# processname: lighttpd
# config: /etc/lighttpd/lighttpd.conf
# config: /etc/sysconfig/lighttpd
# pidfile: /var/run/lighttpd.pid
#
# Note: pidfile is assumed to be created
# by lighttpd (config: server.pid-file).
# If not, uncomment 'pidof' line.
# Source function library
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/lighttpd ]; then
. /etc/sysconfig/lighttpd
fi
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
LIGHTTPD_CONF_PATH="/etc/lighttpd/lighttpd.conf"
fi
prog="lighttpd"
lighttpd="/usr/sbin/lighttpd"
RETVAL=0
start() {
echo "Starting fcgi server"
spawn-fcgi -s /tmp/php-fastcgi.sock -f /usr/bin/php-cgi -ulighttpd -glighttpd -C3 -P /tmp/spawn-fcgi.pid
echo -n $"Starting $prog: "
daemon $lighttpd -f $LIGHTTPD_CONF_PATH
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
stop() {
echo "Stopping fcgi server"
killproc -p /tmp/spawn-fcgi.pid
echo -n $"Stopping $prog: "
killproc -p /var/run/lighttpd.pid
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
reload() {
echo -n $"Reloading $prog: "
killproc $lighttpd -HUP
RETVAL=$?
echo
return $RETVAL
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
reload)
reload
;;
status)
status $lighttpd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
RETVAL=1
esac
exit $RETVAL
%%(bash)
#!/bin/sh
#
# lighttpd Startup script for the lighttpd server
#
# chkconfig: - 85 15
# description: Lightning fast webserver with light system requirements
#
# processname: lighttpd
# config: /etc/lighttpd/lighttpd.conf
# config: /etc/sysconfig/lighttpd
# pidfile: /var/run/lighttpd.pid
#
# Note: pidfile is assumed to be created
# by lighttpd (config: server.pid-file).
# If not, uncomment 'pidof' line.
# Source function library
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/lighttpd ]; then
. /etc/sysconfig/lighttpd
fi
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
LIGHTTPD_CONF_PATH="/etc/lighttpd/lighttpd.conf"
fi
prog="lighttpd"
lighttpd="/usr/sbin/lighttpd"
RETVAL=0
start() {
echo "Starting fcgi server"
spawn-fcgi -s /tmp/php-fastcgi.sock -f /usr/bin/php-cgi -ulighttpd -glighttpd -C3 -P /tmp/spawn-fcgi.pid
echo -n $"Starting $prog: "
daemon $lighttpd -f $LIGHTTPD_CONF_PATH
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
stop() {
echo "Stopping fcgi server"
killproc -p /tmp/spawn-fcgi.pid
echo -n $"Stopping $prog: "
killproc -p /var/run/lighttpd.pid
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
reload() {
echo -n $"Reloading $prog: "
killproc $lighttpd -HUP
RETVAL=$?
echo
return $RETVAL
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
reload)
reload
;;
status)
status $lighttpd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
RETVAL=1
esac
exit $RETVAL
Revision [2231]
Edited on 2009-02-25 06:56:11 by WikiAdminAdditions:
server.network-backend - http://www.lighttpd.net/benchmark
server.network-backend = "gthread-aio" # sendfile() minimizes the work in the application and pushes a file directly into the network card.
# gthread-aio balance between big and small files. posix-aio is good for large files, writev is good for small ones.
server.network-backend = "gthread-aio" # sendfile() minimizes the work in the application and pushes a file directly into the network card.
# gthread-aio balance between big and small files. posix-aio is good for large files, writev is good for small ones.
Deletions:
Revision [2230]
Edited on 2009-02-25 06:55:25 by WikiAdminAdditions:
server.network-backend = "gthread-aio" # sendfile() minimizes the work in the application and pushes a file directly into the network card. **gthread-aio** balance between big and small files. **posix-aio** is good for large files, **writev** is good for small ones.
Deletions:
Revision [2229]
Edited on 2009-02-25 06:51:12 by WikiAdminAdditions:
Server tuning
server.max-fds = 4096 # open files
server.max-worker = 2 # this may cause issue with access logs
server.use-ipv6 = "disable" # no point
server.event-handler = "linux-sysepoll" # linux specific
server.network-backend = "linux-sendfile" # sendfile() minimizes the work in the application and pushes a file directly into the network card
server.max-fds = 4096 # open files
server.max-worker = 2 # this may cause issue with access logs
server.use-ipv6 = "disable" # no point
server.event-handler = "linux-sysepoll" # linux specific
server.network-backend = "linux-sendfile" # sendfile() minimizes the work in the application and pushes a file directly into the network card
Revision [2228]
Edited on 2009-02-25 06:34:12 by WikiAdminAdditions:
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 2,
"max-procs" => 2,
"kill-signal" => 9,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "1000"
))))
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 25,
"max-procs" => 50,
"kill-signal" => 9,
"idle-timeout" => 30,
)))
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 2,
"max-procs" => 2,
"kill-signal" => 9,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "1000"
))))
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 25,
"max-procs" => 50,
"kill-signal" => 9,
"idle-timeout" => 30,
)))
Deletions:
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 2,
"max-procs" => 2,
"kill-signal" => 9,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "1000"
)
)
)
)
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 25,
"max-procs" => 50,
"kill-signal" => 9,
"idle-timeout" => 30,
)
)
)
Revision [2226]
Edited on 2009-02-25 03:01:13 by WikiAdminAdditions:
==php as fastcgi==
==tunings on fastcgi==
# theory 1 - 2 lighttpd processes, many php children. reason for 2 processes is for redundancy. If one process dies, all php children die too.
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 2,
"max-procs" => 2,
"kill-signal" => 9,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "1000"
)
)
)
)
# theory 2 - more lighttpd processes, 1 php child per proc
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 25,
"max-procs" => 50,
"kill-signal" => 9,
"idle-timeout" => 30,
)
)
)
==tunings on fastcgi==
# theory 1 - 2 lighttpd processes, many php children. reason for 2 processes is for redundancy. If one process dies, all php children die too.
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 2,
"max-procs" => 2,
"kill-signal" => 9,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "1000"
)
)
)
)
# theory 2 - more lighttpd processes, 1 php child per proc
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"min-procs" => 25,
"max-procs" => 50,
"kill-signal" => 9,
"idle-timeout" => 30,
)
)
)
Deletions:
Revision [2211]
Edited on 2009-02-18 23:03:19 by WikiAdminAdditions:
==http proxy==
# If no file extension is needed, put "" as the first argument
proxy.server = ( ".jsp" =>
( (
"host" => "10.0.0.242",
"port" => 81
) )
)
# If no file extension is needed, put "" as the first argument
proxy.server = ( ".jsp" =>
( (
"host" => "10.0.0.242",
"port" => 81
) )
)
Revision [2193]
Edited on 2009-02-11 08:43:37 by WikiAdminAdditions:
$HTTP["url"] =~ "^/(tomcat|xwiki)" {
Deletions:
Revision [2086]
Edited on 2008-11-13 19:46:47 by WikiAdminAdditions:
./configure --prefix=/usr --sysconfdir=/etc/lighttpd --disable-ipv6 --with-openssl=/usr
Deletions:
Revision [1873]
Edited on 2008-08-05 23:59:45 by WikiAdminAdditions:
==SSL==
Check that lighttpd has ssl support
> lighttpd -v
lighttpd-1.4.13 (ssl) - a light and fast webserver
Then add these to lighttpd.conf. No need to add 443 to server.port
$SERVER["socket"] == "206.188.19.110:443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/ssl/web.adblade.com.pem"
ssl.ca-file = "/etc/lighttpd/ssl/gd_bundle.crt"
server.name = "web.adblade.com"
server.document-root = "/home/admin/httpdocs"
Check that lighttpd has ssl support
> lighttpd -v
lighttpd-1.4.13 (ssl) - a light and fast webserver
Then add these to lighttpd.conf. No need to add 443 to server.port
$SERVER["socket"] == "206.188.19.110:443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/ssl/web.adblade.com.pem"
ssl.ca-file = "/etc/lighttpd/ssl/gd_bundle.crt"
server.name = "web.adblade.com"
server.document-root = "/home/admin/httpdocs"
Revision [1839]
Edited on 2008-07-22 19:42:19 by WikiAdminAdditions:
==evhost vhost==
evhost is a very powerful vhost configuration tool. if one doesn't wrap the evhost directive around with a socket match, it will serve request for 0.0.0.0:*. Not a problem if all the sites are ran on the same IP and no SSL sites are served. Otherwise, the following example uses evhosts in conjunction with simple vhost to serve plain and secure sites:
$SERVER["socket"] == "0.0.0.0:80" {
evhost.path-pattern = "/home/sites/www.%0/web/"
$SERVER["socket"] == "1.2.3.4:443" {
ssl.engine = "enable"
ssl.pemfile = "/home/sites/www.domain.tld.pem"
server.document-root = "/home/sites/www.domain.tld/web"
evhost variable:
%0 => domain name + tld
%1 => tld
%2 => domain name without tld
%3 => subdomain 1 name
%4 => subdomain 2 name
evhost is a very powerful vhost configuration tool. if one doesn't wrap the evhost directive around with a socket match, it will serve request for 0.0.0.0:*. Not a problem if all the sites are ran on the same IP and no SSL sites are served. Otherwise, the following example uses evhosts in conjunction with simple vhost to serve plain and secure sites:
$SERVER["socket"] == "0.0.0.0:80" {
evhost.path-pattern = "/home/sites/www.%0/web/"
$SERVER["socket"] == "1.2.3.4:443" {
ssl.engine = "enable"
ssl.pemfile = "/home/sites/www.domain.tld.pem"
server.document-root = "/home/sites/www.domain.tld/web"
evhost variable:
%0 => domain name + tld
%1 => tld
%2 => domain name without tld
%3 => subdomain 1 name
%4 => subdomain 2 name
Revision [1797]
Edited on 2008-07-04 02:25:13 by WikiAdminAdditions:
==simple vhost==
$HTTP["host"] =~ "domain1\.com" {
server.document-root = "/home/lighttpd/domain1.com/http"
accesslog.filename = "/home/lighttpd/domain1.com/logs/access.log"
$HTTP["host"] =~ "domain1\.com" {
server.document-root = "/home/lighttpd/domain1.com/http"
accesslog.filename = "/home/lighttpd/domain1.com/logs/access.log"
Revision [1701]
Edited on 2008-04-24 21:05:21 by WikiAdminAdditions:
$HTTP["querystring"] == "page=home" {
$HTTP["url"] =~ "^/home.html" {
url.redirect = ( "^/(.*)" => "/index.html" )
}
}
$HTTP["url"] =~ "^/home.html" {
url.redirect = ( "^/(.*)" => "/index.html" )
}
}
Revision [1639]
Edited on 2008-04-12 07:55:23 by WikiAdminAdditions:
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php-fcgi/bin/php"
)
server.modules += ( "mod_proxy_core", "mod_proxy_backend_ajp13" )
url.redirect = ( "(.*)" => "www.mentalhelp.net$1" )
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php-fcgi/bin/php"
)
server.modules += ( "mod_proxy_core", "mod_proxy_backend_ajp13" )
url.redirect = ( "(.*)" => "www.mentalhelp.net$1" )
Deletions:
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php-fcgi/bin/php"
)
server.modules += ( "mod_proxy_backend_ajp13" )
url.redirect = ( "(.*)" => "www.mentalhelp.net$1" )
Revision [1425]
Edited on 2008-02-28 23:29:46 by WikiAdminAdditions:
==Redirect==
$HTTP["url"] !~ "^/admin" {
url.redirect = ( "(.*)" => "www.mentalhelp.net$1" )
}
$HTTP["url"] !~ "^/admin" {
url.redirect = ( "(.*)" => "www.mentalhelp.net$1" )
}
Revision [985]
Edited on 2007-09-28 00:23:22 by WikiAdminNo differences.
Revision [984]
Edited on 2007-09-28 00:22:05 by WikiAdminAdditions:
==php (lighttpd 1.5+)==
Run a fastcgi background process, and use mod_proxy to connect to it.
/usr/bin/spawn-fcgi -s /tmp/php-fastcgi.sock -f /usr/bin/php-cgi -uwww -g www -C 5 -P /var/run/spawn-fcgi.pid
%%(apache;lighttpd.conf)
server.modules += ( "mod_proxy_backend_fastcgi" )
$HTTP["url"] =~ "\.php$" {
proxy-core.balancer = "round-robin"
proxy-core.allow-x-sendfile = "enable"
# proxy-core.check-local = "enable"
proxy-core.protocol = "fastcgi"
proxy-core.backends = ( "unix:/tmp/php-fastcgi.sock" )
proxy-core.max-pool-size = 16
Run a fastcgi background process, and use mod_proxy to connect to it.
/usr/bin/spawn-fcgi -s /tmp/php-fastcgi.sock -f /usr/bin/php-cgi -uwww -g www -C 5 -P /var/run/spawn-fcgi.pid
%%(apache;lighttpd.conf)
server.modules += ( "mod_proxy_backend_fastcgi" )
$HTTP["url"] =~ "\.php$" {
proxy-core.balancer = "round-robin"
proxy-core.allow-x-sendfile = "enable"
# proxy-core.check-local = "enable"
proxy-core.protocol = "fastcgi"
proxy-core.backends = ( "unix:/tmp/php-fastcgi.sock" )
proxy-core.max-pool-size = 16