website view en/doc/handbook/web-server.html @ rev 41

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