website view en/doc/handbook/web-server.html @ rev 40
Tidy up Web Server - Handbook (en)
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Thu May 05 12:59:13 2011 +0000 (2011-05-05) |
parents | e172c1d2ec01 |
children | b7363623c8eb |
line source
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>SliTaz Handbook (en) - Template</title>
6 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
7 <meta name="description" content="slitaz English handbook" />
8 <meta name="expires" content="never" />
9 <meta name="modified" content="2008-02-26 18:30:00" />
10 <meta name="publisher" content="www.slitaz.org" />
11 <meta name="author" content="Christophe Lincoln" />
12 <link rel="shortcut icon" href="favicon.ico" />
13 <link rel="stylesheet" type="text/css" href="book.css" /></head><body bgcolor="#ffffff">
15 <!-- Header and quick navigation -->
16 <div id="header">
17 <div id="quicknav" align="right">
18 <a name="top"></a>
19 <a href="index.html">Table of contents</a>
20 </div>
21 <h1><font color="#3e1220">SliTaz Handbook (en)</font></h1>
22 </div>
24 <!-- Content. -->
25 <div id="content">
26 <div class="content-right"></div>
28 <h2><font color="#df8f06">LightTPD Web Server</font></h2>
30 <ul>
31 <li><a href="#about">About LightTPD.</a></li>
32 <li><a href="#var-www">/var/www</a> - Root directory of documents.</li>
33 <li><a href="#Public">~/Public</a> - Public directory of users.</li>
34 <li><a href="#config">lighttpd.conf</a> - LightTPD Configuration File.</li>
35 <li><a href="#start-stop-restart">Start, stop, restart the server.</a></li>
36 <li><a href="#cgi-perl">Scripts CGI and Perl</a> - CGI scripts using Perl.</li>
37 <li><a href="#cgi-python">Scripts CGI and Python</a> - CGI scripts using Python.</li>
38 <li><a href="#auth">Authentication</a> - Protect directories using username and password.</li>
39 </ul>
41 <a name="about"></a>
42 <h3>About LightTPD</h3>
43 <p>
44 This chapter describes the configuration and use of the LightTPD web server. It's a fast, secure, flexible HTTP
45 server, using a small memory footprint. It enables intelligent management of the cpu load and offers
46 FastCGI support, CGI, Auth, Output compression and the rewriting of URLs etc. LightTPD is a cheap way to host your
47 own site on an old machine.
48 </p>
49 <p>
50 On SliTaz the server is automatically launched at system startup and is preconfigured with PHP. The root
51 of the documents served by default are in <code>/var/www</code> and contain a default page <code>index.html</code>,
52 images are stored in the <code>images/</code> directory.
53 LightTPD website: <a href="http://www.lighttpd.net/">http://www.lighttpd.net/</a>
54 </p>
55 <a name="var-www"></a>
56 <h3>/var/www - Root directory of documents</h3>
57 <p>
58 The directory /var/www is the root directory of documents - you can access this via the URL
59 <a href="http://localhost/">http://localhost/</a>. If you want to host a site, you can save all your documents
60 in here. If you want to host multiple sites, you'll need to create virtual hosts. Note you can also check the
61 <a href="http://localhost/server-status">http://localhost/server-status</a>.
63 </p>
64 <a name="Public"></a>
65 <h3>~/Public - Public directory of users</h3>
66 <p>
67 SliTaz provides the users of the system a public space to place documents, HTML in general.
68 This directory is named Public and must be within the root of your user space, such as /home/hacker/Public.
69 To create this directory use the mkdir command:
70 </p>
71 <pre> $ mkdir ~/Public
72 </pre>
73 <p>
74 You can then have access via the URL:
75 <a href="http://localhost/%7Ehacker/">http://localhost/~hacker/</a>. You can also use the machine name or IP
76 address if you connect from another computer.
77 </p>
78 <a name="config"></a>
79 <h3>/etc/lighttpd/lighttpd.conf - LightTPD configuration file</h3>
80 <p>
81 The main configuration file for LightTPD (<code>lighttpd.conf</code>) is located in /etc/lighttpd/. This file provided by
82 SliTaz is self-explanatory, just browse. You can find other examples on the LightTPD website. On
83 SliTaz you'll also find a <code>vhosts.conf</code> file for the configuration of any virtual hosts (hosting
84 several sites on the same server).
85 </p>
86 <a name="start-stop-restart"></a>
87 <h3>Start, stop, restart the web server</h3>
88 <p>
89 By default, SliTaz starts the server automatically at boot, to prevent this you need to remove
90 <code>lighttpd</code> from the variable RUN_DAEMONS located in the system file
91 <code>/etc/rcS.conf</code>. To start, stop, restart the server; you can use the commands:
92 <code>/etc/init.d/lighttpd [start|stop|restart]</code>. Example to restart the server after
93 changing the configuration file:
94 </p>
95 <pre> # /etc/init.d/lighttpd restart
96 </pre>
98 <a name="cgi-perl"></a>
99 <h3>CGI scripts using Perl</h3>
100 <p>
101 To configure the LightTPD server to locate the path of the <code>perl</code> binary and use CGI/Perl, you'll need to
102 install perl and modify the server configuration file. Example using Geany:
103 </p>
104 <pre> # tazpkg get-install perl
105 # geany /etc/lighttpd/lighttpd.conf &
106 </pre>
107 <pre class="script"># CGI module. You can install Perl and assign .pl and .cgi scripts
108 # to /usr/bin/perl
109 $HTTP["url"] =~ "/cgi-bin/" {
110 cgi.assign = (
111 ".sh" => "/bin/sh",
112 ".cgi" => "/usr/bin/perl,
113 ".pl" => "/usr/bin/perl
114 )
115 }
116 </pre>
118 <a name="cgi-python"></a>
119 <h3>CGI scripts using Python</h3>
120 <p>
121 To configure the LightTPD server to locate the path of the <code>python</code> binary and use CGI/Python, you'll need to
122 to install python and modify the server configuration file. Example using Geany:
123 </p>
124 <pre> # tazpkg get-install python
125 # geany /etc/lighttpd/lighttpd.conf &
126 </pre>
127 <pre class="script"># CGI module. You can install Python and assign .py and .cgi scripts
128 # to /usr/bin/python
129 $HTTP["url"] =~ "/cgi-bin/" {
130 cgi.assign = (
131 ".sh" => "/bin/sh",
132 ".cgi" => "/usr/bin/python,
133 ".py" => "/usr/bin/python
134 )
135 }
136 </pre>
137 <p>
138 For the changes to be taken into effect and to use your first CGI scripts on SliTaz, just
139 restart the LightTPD server:
140 </p>
141 <pre> # /etc/init.d/lighttpd restart
142 </pre>
144 <a name="auth"></a>
145 <h3>Authentication - Protection for the directories</h3>
146 <p>
147 LightTPD provides authentication modules that can for example, protect a directory. The server
148 offers several authentication methods, but we will begin by using the basic method without encrypting any
149 passwords. In order to be able to use the module <code>mod_auth</code>, you must install the lighttpd-modules
150 package (<code>tazpkg get-install lighttpd-modules</code>), once installed <code>mod_auth</code>
151 must be added to the list of modules:
152 </p>
153 <pre class="script"># Modules to load.
154 # See /usr/lib/lighttpd for all available modules.
155 #
156 server.modules = (
157 "mod_access",
158 "mod_auth",
159 "...",
160 )
161 </pre>
162 <p>
163 Now you can configure the modules by specifying the debug level and method (<code>plain</code>) and the
164 path to the file containing a list of names using a protected password to access the directories. You must also
165 define the directories that require authorization. In this example we'll protect the <code>admin/</code> directory
166 and authorise it's access to user hacker (<code>user=hacker</code>):
167 </p>
168 <pre class="script"># Authentification for protected directory.
169 auth.debug = 2
170 auth.backend = "plain"
171 auth.backend.plain.userfile = "/etc/lighttpd/plain.passwd"
172 auth.require = ( "/admin/" =>
173 (
174 "method" => "basic",
175 "realm" => "Password protected area",
176 "require" => "user=hacker"
177 )
178 )
179 </pre>
180 <p>
181 Finally, we now create the file containing the passwords, add a user and restart the server for testing.
182 The basic syntax for the file is <code>user:password</code>. You can create the file and add a user with the
183 <code>echo</code> command or edit with your favorite text editor. To add <code>hacker:root</code>
184 to the password file <code>/etc/lighttpd/plain.passwd</code>:
185 </p>
186 <pre> # echo "hacker:root" > /etc/lighttpd/plain.passwd
187 Or :
188 # nano /etc/lighttpd/plain.passwd
189 </pre>
190 <p>
191 To test the address: http://localhost/admin/, just restart the server:
192 </p>
193 <pre> # /etc/init.d/lighttpd restart
194 </pre>
196 <!-- End of content -->
197 </div>
199 <!-- Footer. -->
200 <div id="footer">
201 <div class="footer-right"></div>
202 <a href="#top">Top of the page</a> |
203 <a href="http://www.slitaz.org/en/doc/handbook/index.html">Table of contents</a>
204 </div>
206 <div id="copy">
207 Copyright © 2008 <a href="http://www.slitaz.org/en/">SliTaz</a> -
208 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>;<br />
209 Documentation is under
210 <a href="http://www.gnu.org/copyleft/fdl.html">GNU Free Documentation License</a>
211 and code is <a href="http://validator.w3.org/">valid xHTML 1.0</a>.
212 </div>
214 </body></html>