Difference between revisions of "Beef up your second instance of thttpd with redirects and Server Side Includes"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
(How to use Server Side Includes with thttpd)
 
Line 1: Line 1:
dummy
+
''<font color=red><small>
 +
This article
 +
Based on work by andre.
 +
Originally by andre.
 +
</small></font>''
 +
 
 +
=== Server Side Includes (SSI) and Redirection with thttpd ===
 +
 
 +
<strong>SSI</strong> is code executed by the server before a page is delivered. For example, you could automatically include a footer into an HTML document, or display its path and modification date.
 +
 
 +
<strong>Redirection</strong> means you request one document and are served another.
 +
 
 +
<strong>thttpd</strong> is the web server that comes with the Linkstation; the example configuration will assume you're using the second instance thttpd2, as described in [[Articles/GeneralThttpd]].
 +
 
 +
== Requirements ==
 +
 
 +
Thttpd comes with two auxiliary programs, "redirect" and "ssi", which we'll use to serve ".shtml" pages (as SSI enabled pages are usually called).
 +
 
 +
This example configuration for an LS1 will serve web content with from /mnt/share/www. On the LS2, you will probably use /mnt/hda/share/www instead.
 +
 
 +
* On Debian, the programs "redirect" and "ssi" reside in /usr/lib/cgi-bin/ if "thttpd-util" is installed.
 +
 
 +
* On OpenLink, you will need to locate these programs yourself for the time being.
 +
 
 +
mkdir /mnt/share/www # this is our server root
 +
mkdir /mnt/share/www/cgi-bin
 +
mkdir /mnt/share/www/ssi
 +
cp /usr/lib/cgi-bin/redirect /mnt/www/cgi-bin/redirect.cgi # on Debian
 +
cp /usr/lib/cgi-bin/ssi /mnt/www/cgi-bin/ssi.cgi # on Debian
 +
touch /mnt/share/www/cgi-bin/.redirects
 +
 
 +
The relevant parts of /etc/thttpd2.conf read:
 +
 
 +
port=81
 +
nochroot # cgi!
 +
user=nobody # cgi!
 +
dir=/mnt/share/www # this is our server root
 +
cgipat=/cgi-bin/*.cgi
 +
charset=utf-8
 +
 
 +
== Redirection ==
 +
 
 +
<strong>You cannot redirect index.html with thttpd!!!</strong>
 +
 
 +
Having said that, we want to redirect users to the linkstationwiki.net if they click on the file "community.html" on our website; linking to this file is possible.
 +
 
 +
cd /mnt/share/www # this is our server root
 +
mv community.html 2>/tmp/ # make sure there's no offending file
 +
ln -s cgi-bin/redirect.cgi community.html
 +
echo '/community.html http://linkstationwiki.net' >> cgi-bin/.redirects
 +
 
 +
See "man redirect" for more information (good luck, it was the reason why I wrote this document)
 +
 
 +
== Server Side Includes ==
 +
 
 +
We want to display the modification date of "mod.txt" in the directory "docs" on our web server automatically. Of course this also works for HTML documents, this is just an example.
 +
 
 +
cd /mnt/share/www # this is our server root
 +
mkdir docs
 +
cd docs
 +
echo '&lt;!--#echo var="LAST_MODIFIED" --&gt;' > mod.txt # create the file
 +
mv mod.txt ../ssi/mod.shtml
 +
ln -s ../cgi-bin/redirect.cgi mod.txt
 +
echo '/docs/mod.txt /cgi-bin/ssi.cgi/ssi/mod.shtml' >> ../cgi-bin/.redirects
 +
 
 +
See "man ssi" for details and more variables, how to include files, and more about SSIs.
 +
 
 +
[[Category:General]]
 +
[[Category:Howto]]

Revision as of 12:42, 7 July 2006

This article Based on work by andre. Originally by andre.

Contents

Server Side Includes (SSI) and Redirection with thttpd

SSI is code executed by the server before a page is delivered. For example, you could automatically include a footer into an HTML document, or display its path and modification date.

Redirection means you request one document and are served another.

thttpd is the web server that comes with the Linkstation; the example configuration will assume you're using the second instance thttpd2, as described in Articles/GeneralThttpd.

Requirements

Thttpd comes with two auxiliary programs, "redirect" and "ssi", which we'll use to serve ".shtml" pages (as SSI enabled pages are usually called).

This example configuration for an LS1 will serve web content with from /mnt/share/www. On the LS2, you will probably use /mnt/hda/share/www instead.

  • On Debian, the programs "redirect" and "ssi" reside in /usr/lib/cgi-bin/ if "thttpd-util" is installed.
  • On OpenLink, you will need to locate these programs yourself for the time being.
mkdir /mnt/share/www # this is our server root
mkdir /mnt/share/www/cgi-bin
mkdir /mnt/share/www/ssi
cp /usr/lib/cgi-bin/redirect /mnt/www/cgi-bin/redirect.cgi # on Debian
cp /usr/lib/cgi-bin/ssi /mnt/www/cgi-bin/ssi.cgi # on Debian
touch /mnt/share/www/cgi-bin/.redirects

The relevant parts of /etc/thttpd2.conf read:

port=81
nochroot # cgi!
user=nobody # cgi!
dir=/mnt/share/www # this is our server root
cgipat=/cgi-bin/*.cgi
charset=utf-8

Redirection

You cannot redirect index.html with thttpd!!!

Having said that, we want to redirect users to the linkstationwiki.net if they click on the file "community.html" on our website; linking to this file is possible.

cd /mnt/share/www # this is our server root
mv community.html 2>/tmp/ # make sure there's no offending file
ln -s cgi-bin/redirect.cgi community.html
echo '/community.html http://linkstationwiki.net' >> cgi-bin/.redirects

See "man redirect" for more information (good luck, it was the reason why I wrote this document)

Server Side Includes

We want to display the modification date of "mod.txt" in the directory "docs" on our web server automatically. Of course this also works for HTML documents, this is just an example.

cd /mnt/share/www # this is our server root
mkdir docs
cd docs
echo '<!--#echo var="LAST_MODIFIED" -->' > mod.txt # create the file
mv mod.txt ../ssi/mod.shtml
ln -s ../cgi-bin/redirect.cgi mod.txt
echo '/docs/mod.txt /cgi-bin/ssi.cgi/ssi/mod.shtml' >> ../cgi-bin/.redirects

See "man ssi" for details and more variables, how to include files, and more about SSIs.