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