rev |
line source |
slaxemulator@7
|
1 ====== LightTPD Web Server ======
|
slaxemulator@7
|
2
|
slaxemulator@7
|
3 ===== About LightTPD =====
|
slaxemulator@7
|
4
|
slaxemulator@7
|
5 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.
|
slaxemulator@7
|
6
|
slaxemulator@7
|
7 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/
|
slaxemulator@7
|
8
|
slaxemulator@7
|
9 ===== /var/www - Root directory of documents =====
|
slaxemulator@7
|
10
|
slaxemulator@7
|
11 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.
|
slaxemulator@7
|
12
|
slaxemulator@7
|
13
|
slaxemulator@7
|
14 ===== ~Public - Public directory of users =====
|
slaxemulator@7
|
15
|
slaxemulator@7
|
16 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:
|
slaxemulator@7
|
17
|
slaxemulator@7
|
18 <code> $ mkdir ~/Public </code>
|
slaxemulator@7
|
19
|
slaxemulator@7
|
20 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.
|
slaxemulator@7
|
21
|
slaxemulator@7
|
22 =====/etc/lighttpd/lighttpd.conf - LightTPD configuration file=====
|
slaxemulator@7
|
23
|
slaxemulator@7
|
24 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).
|
slaxemulator@7
|
25
|
slaxemulator@7
|
26 =====Start, stop, restart the web server=====
|
slaxemulator@7
|
27
|
slaxemulator@7
|
28 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:
|
slaxemulator@7
|
29
|
slaxemulator@7
|
30 <code> # /etc/init.d/lighttpd restart </code>
|
slaxemulator@7
|
31
|
slaxemulator@7
|
32 ===== CGI scripts using Perl =====
|
slaxemulator@7
|
33
|
slaxemulator@7
|
34 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:
|
slaxemulator@7
|
35
|
slaxemulator@7
|
36 <code> # tazpkg get-install perl
|
slaxemulator@7
|
37 # geany /etc/lighttpd/lighttpd.conf & </code>
|
slaxemulator@7
|
38
|
slaxemulator@7
|
39
|
slaxemulator@7
|
40 <file>
|
slaxemulator@7
|
41 # CGI module. You can install Perl and assign .pl and .cgi scripts
|
slaxemulator@7
|
42 # to /usr/bin/perl
|
slaxemulator@7
|
43 $HTTP["url"] =~ "/cgi-bin/" {
|
slaxemulator@7
|
44 cgi.assign = (
|
slaxemulator@7
|
45 ".sh" => "/bin/sh",
|
slaxemulator@7
|
46 ".cgi" => "/usr/bin/perl,
|
slaxemulator@7
|
47 ".pl" => "/usr/bin/perl
|
slaxemulator@7
|
48 )
|
slaxemulator@7
|
49 }
|
slaxemulator@7
|
50
|
slaxemulator@7
|
51 </file>
|
slaxemulator@7
|
52
|
slaxemulator@7
|
53 ===== CGI scripts using Python =====
|
slaxemulator@7
|
54
|
slaxemulator@7
|
55 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:
|
slaxemulator@7
|
56 <code>
|
slaxemulator@7
|
57 # tazpkg get-install python
|
slaxemulator@7
|
58 # geany /etc/lighttpd/lighttpd.conf &
|
slaxemulator@7
|
59 </code>
|
slaxemulator@7
|
60
|
slaxemulator@7
|
61 <file>
|
slaxemulator@7
|
62 # CGI module. You can install Python and assign .py and .cgi scripts
|
slaxemulator@7
|
63 # to /usr/bin/python
|
slaxemulator@7
|
64 $HTTP["url"] =~ "/cgi-bin/" {
|
slaxemulator@7
|
65 cgi.assign = (
|
slaxemulator@7
|
66 ".sh" => "/bin/sh",
|
slaxemulator@7
|
67 ".cgi" => "/usr/bin/python,
|
slaxemulator@7
|
68 ".py" => "/usr/bin/python
|
slaxemulator@7
|
69 )
|
slaxemulator@7
|
70 }
|
slaxemulator@7
|
71 </file>
|
slaxemulator@7
|
72
|
slaxemulator@7
|
73 For the changes to be taken into effect and to use your first CGI scripts on SliTaz, just restart the LightTPD server:
|
slaxemulator@7
|
74
|
slaxemulator@7
|
75 <code> # /etc/init.d/lighttpd restart </code>
|
slaxemulator@7
|
76
|
slaxemulator@7
|
77 ===== Authentication - Protection for the directories =====
|
slaxemulator@7
|
78
|
slaxemulator@7
|
79 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:
|
slaxemulator@7
|
80
|
slaxemulator@7
|
81 <file>
|
slaxemulator@7
|
82 # Modules to load.
|
slaxemulator@7
|
83 # See /usr/lib/lighttpd for all available modules.
|
slaxemulator@7
|
84 #
|
slaxemulator@7
|
85 server.modules = (
|
slaxemulator@7
|
86 "mod_access",
|
slaxemulator@7
|
87 "mod_auth",
|
slaxemulator@7
|
88 "...",
|
slaxemulator@7
|
89 )
|
slaxemulator@7
|
90 </file>
|
slaxemulator@7
|
91
|
slaxemulator@7
|
92 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//):
|
slaxemulator@7
|
93
|
slaxemulator@7
|
94 <file>
|
slaxemulator@7
|
95 # Authentication for protected directory.
|
slaxemulator@7
|
96 auth.debug = 2
|
slaxemulator@7
|
97 auth.backend = "plain"
|
slaxemulator@7
|
98 auth.backend.plain.userfile = "/etc/lighttpd/plain.passwd"
|
slaxemulator@7
|
99 auth.require = ( "/admin/" =>
|
slaxemulator@7
|
100 (
|
slaxemulator@7
|
101 "method" => "basic",
|
slaxemulator@7
|
102 "realm" => "Password protected area",
|
slaxemulator@7
|
103 "require" => "user=tux"
|
slaxemulator@7
|
104 )
|
slaxemulator@7
|
105 )
|
slaxemulator@7
|
106 </file>
|
slaxemulator@7
|
107
|
slaxemulator@7
|
108 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//:
|
slaxemulator@7
|
109
|
slaxemulator@7
|
110 <code>
|
slaxemulator@7
|
111 # echo "tux:root" > /etc/lighttpd/plain.passwd
|
slaxemulator@7
|
112 Or :
|
slaxemulator@7
|
113 # nano /etc/lighttpd/plain.passwd
|
slaxemulator@7
|
114 </code>
|
slaxemulator@7
|
115 To test the address: **http://localhost/admin/**, just restart the server:
|
slaxemulator@7
|
116
|
slaxemulator@7
|
117 <code> # /etc/init.d/lighttpd restart </code> |