slitaz-doc-wiki-data diff pages/en/handbook/webserver.txt @ rev 7
Add pages/en folder.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sat Feb 26 12:17:18 2011 +0000 (2011-02-26) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pages/en/handbook/webserver.txt Sat Feb 26 12:17:18 2011 +0000 1.3 @@ -0,0 +1,117 @@ 1.4 +====== LightTPD Web Server ====== 1.5 + 1.6 +===== About LightTPD ===== 1.7 + 1.8 +This chapter describes the configuration and use of the LightTPD web server. It's a fast, secure, flexible HTTP server, using a small memory footprint. It enables intelligent management of the cpu load and offers FastCGI support, CGI, Auth, Output compression and the rewriting of URLs, etc. LightTPD is a cheap way to host your own site on an old machine. 1.9 + 1.10 +On SliTaz the server is automatically launched at system startup and is preconfigured with PHP. The root documents served by default are in /var/www, this contains the default page index.html, images are stored in the images/ directory. LightTPD website: http://www.lighttpd.net/ 1.11 + 1.12 +===== /var/www - Root directory of documents ===== 1.13 + 1.14 +The /var/www folder is the root directory of documents - you can access this via the URL http://localhost/. If you want to host a site, you can save all your documents in here. If you want to host multiple sites, you'll need to create virtual hosts. Note you can also check the http://localhost/server-status. 1.15 + 1.16 + 1.17 +===== ~Public - Public directory of users ===== 1.18 + 1.19 +SliTaz provides the users of the system a public space to place documents, HTML in general. This directory is named Public and must be within the root of your user space, such as ///home/hacker/Public//. To create this directory, use the //mkdir// command: 1.20 + 1.21 +<code> $ mkdir ~/Public </code> 1.22 + 1.23 +You can then have access via the URL: http://localhost/~hacker/. You can also use the machine name or IP address if you connect from another computer. 1.24 + 1.25 +=====/etc/lighttpd/lighttpd.conf - LightTPD configuration file===== 1.26 + 1.27 +The main configuration file for LightTPD (lighttpd.conf) is located in ///etc/lighttpd///. This file provided by SliTaz is self-explanatory, just browse. You can find other examples on the LightTPD website. On SliTaz you'll also find a //vhosts.conf// file for the configuration of any virtual hosts (hosting several sites on the same server). 1.28 + 1.29 +=====Start, stop, restart the web server===== 1.30 + 1.31 +By default, SliTaz starts the server automatically at boot, to prevent this you need to remove lighttpd from the variable //RUN_DAEMONS// located in the system file ///etc/rcS.conf//. To start, stop or restart the server, you can use the commands: ///etc/init.d/lighttpd [start|stop|restart]//. Example to restart the server after changing the configuration file: 1.32 + 1.33 +<code> # /etc/init.d/lighttpd restart </code> 1.34 + 1.35 +===== CGI scripts using Perl ===== 1.36 + 1.37 +To configure the LightTPD server to locate the path of the perl binary and use CGI/Perl, you'll need to install perl and modify the server configuration file. Example using Geany: 1.38 + 1.39 +<code> # tazpkg get-install perl 1.40 + # geany /etc/lighttpd/lighttpd.conf & </code> 1.41 + 1.42 + 1.43 +<file> 1.44 +# CGI module. You can install Perl and assign .pl and .cgi scripts 1.45 +# to /usr/bin/perl 1.46 +$HTTP["url"] =~ "/cgi-bin/" { 1.47 + cgi.assign = ( 1.48 + ".sh" => "/bin/sh", 1.49 + ".cgi" => "/usr/bin/perl, 1.50 + ".pl" => "/usr/bin/perl 1.51 + ) 1.52 +} 1.53 + 1.54 +</file> 1.55 + 1.56 +===== CGI scripts using Python ===== 1.57 + 1.58 +To configure the LightTPD server to locate the path of the python binary and use CGI/Python, you'll need to to install python and modify the server configuration file. Example using Geany: 1.59 +<code> 1.60 + # tazpkg get-install python 1.61 + # geany /etc/lighttpd/lighttpd.conf & 1.62 +</code> 1.63 + 1.64 +<file> 1.65 +# CGI module. You can install Python and assign .py and .cgi scripts 1.66 +# to /usr/bin/python 1.67 +$HTTP["url"] =~ "/cgi-bin/" { 1.68 + cgi.assign = ( 1.69 + ".sh" => "/bin/sh", 1.70 + ".cgi" => "/usr/bin/python, 1.71 + ".py" => "/usr/bin/python 1.72 + ) 1.73 +} 1.74 +</file> 1.75 + 1.76 +For the changes to be taken into effect and to use your first CGI scripts on SliTaz, just restart the LightTPD server: 1.77 + 1.78 +<code> # /etc/init.d/lighttpd restart </code> 1.79 + 1.80 +===== Authentication - Protection for the directories ===== 1.81 + 1.82 +LightTPD provides authentication modules that can for example, protect a directory. The server offers several authentication methods, but we will begin by using the basic method without encrypting any passwords. In order to be able to use the module mod_auth, you must install the lighttpd-modules package (tazpkg get-install lighttpd-modules). Once installed mod_auth must be added to the list of modules: 1.83 + 1.84 +<file> 1.85 +# Modules to load. 1.86 +# See /usr/lib/lighttpd for all available modules. 1.87 +# 1.88 +server.modules = ( 1.89 + "mod_access", 1.90 + "mod_auth", 1.91 + "...", 1.92 +) 1.93 +</file> 1.94 + 1.95 +Now you can configure the modules by specifying the debug level and method (plain) and the path to the file containing a list of names using a protected password to access the directories. You must also define the directories that require authorization. In this example we'll protect the admin/ directory and authorize its access to user tux (//user=tux//): 1.96 + 1.97 +<file> 1.98 +# Authentication for protected directory. 1.99 +auth.debug = 2 1.100 +auth.backend = "plain" 1.101 +auth.backend.plain.userfile = "/etc/lighttpd/plain.passwd" 1.102 +auth.require = ( "/admin/" => 1.103 +( 1.104 +"method" => "basic", 1.105 +"realm" => "Password protected area", 1.106 +"require" => "user=tux" 1.107 +) 1.108 +) 1.109 +</file> 1.110 + 1.111 +Finally, we now create the file containing the passwords, add a user and restart the server for testing. The basic syntax for the file is user:password. You can create the file and add a user with the echo command or edit with your favorite text editor. To add tux:root to the password file ///etc/lighttpd/plain.passwd//: 1.112 + 1.113 +<code> 1.114 + # echo "tux:root" > /etc/lighttpd/plain.passwd 1.115 + Or : 1.116 + # nano /etc/lighttpd/plain.passwd 1.117 +</code> 1.118 +To test the address: **http://localhost/admin/**, just restart the server: 1.119 + 1.120 +<code> # /etc/init.d/lighttpd restart </code> 1.121 \ No newline at end of file