sudo apt-get install lighttpd php5-cgi
sudo lighty-enable-mod fastcgi sudo lighty-enable-mod simple-vhost sudo lighty-enable-mod ssl
Lighttpd neustarten:
sudo /etc/init.d/lighttpd force-reload
Für diese Konfiguration wird folgende Verzeichnisstruktur erwartet:
/var/www/servers/example.com/htdocs
sudo vim /etc/lighttpd/conf-available/10-simple-vhost.conf simple-vhost.server-root = "/var/www/servers/" simple-vhost.document-root = "/htdocs/" simple-vhost.default-host = "example.com"
Diese Zeile am Ende der '10-simple-vhost.conf' einfügen:
include_shell "/var/www/servers/config_servers"
Anschließend wird die angegebene Datei erstellt und mit folgendem Inhalt gefüllt:
#!/bin/bash for VHOST in `find /var/www/servers/ -mindepth 1 -maxdepth 1 \( -type d -or -type l \) -exec test -e "{}/server.conf" \; -exec basename "{}" \; 2>/dev/null` ; do { echo "\$HTTP[\"host\"] == \"$VHOST\" {" echo "var.vhost_name = \"$VHOST\"" echo "var.vhost_path = \"/var/www/servers/$VHOST\"" cat "/var/www/servers/$VHOST/server.conf" echo "server.errorlog = \"/var/www/servers/$VHOST/logs/error.log\"", echo "accesslog.filename = \"/var/www/servers/$VHOST/logs/access.log\"" echo "}" } ; done
Anschließend die Datei ausführbar machen:
sudo chmod a+x /var/www/servers/config_servers
Die Konfigurationsdatei sollte dann z.B. unter '/var/www/servers/example.com/server.conf' liegen. Syntax der Konfigurationsdatei entspricht der Standard-Lighty-Syntax.
cd /etc/lighttpd sudo openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
Mit diesem Skript können einfach und schnell neue virtuelle Hosts angelegt werden. Einfach in eine neue Datei kopieren und mit
chmod +x newhost
ausführbar machen. Aufgerufen wird das ganze so:
sudo newhost example.com
'example.com' dabei durch die gewünschte Domain für den vHost ersetzen.
#!/bin/bash # Script for creating new virtual hosts for the # lighttpd setup described here: # http://www.zeroathome.de/wordpress/lighttpd-mit-vhosts-unter-ubuntu-hardy/ # Version 0.1 # # This script is licensed under the MIT License # see http://www.opensource.org/licenses/mit-license.php # Configuration # Where are the vhost directories? wwwroot='/var/www/servers' # Who is the webserver user? wwwuser='www-data' wwwgroup='www-data' if [ "$1" == "" ]; then echo "Please specify a hostname" echo "Usage:" echo "newhost example.tld" else # Check for superuser priviliges if [ "$USER" != 'root' ]; then echo "Error: You are calling this script without root-permissions." >&2 echo "Please start this with sudo in front" >&2 exit 1 fi # Create log and htdocs directory mkdir -p $wwwroot/$1/{logs,htdocs}/ # Create server.conf and user access file (for using it see http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModAuth) touch $wwwroot/$1/{server.conf,$1-users.txt} echo " ## Please uncomment the following lines to enable plain-text access restrictions ## You will have to specify valid users in $1-users.txt. ## This can easily be done using the 'htpasswd' utility from the package 'apache-utils' #auth.backend = \"plain\" #auth.backend.plain.userfile = \"$wwwroot/$1/$1-users.txt\" #auth.require = (\"/\" => ( # \"method\" => \"basic\", # \"realm\" => \"Private\", # \"require\" => \"valid-user\" #))" > $wwwroot/$1/server.conf # Hand the directories and files over to the webserver user chown -R $wwwuser:$wwwgroup $wwwroot/$1 echo "vHost $1 successfully created" echo "Add configuration to $wwwroot/$1/server.conf if necessary" fi