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

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