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
m (Server Side Includes (SSI) and Redirection with thttpd)
(Server Side Includes)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
''<font color=red><small>
+
{{Template:Articles}}''<font color=red><small>
 
This article  
 
This article  
 
Based on work by andre.
 
Based on work by andre.
Line 5: Line 5:
 
</small></font>''
 
</small></font>''
  
=== Server Side Includes (SSI) and Redirection with thttpd ===
+
= 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>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.  
Line 22: Line 22:
  
 
* On OpenLink, you will need to locate these programs yourself for the time being.
 
* 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:
 
The relevant parts of /etc/thttpd2.conf read:
Line 38: Line 31:
 
  cgipat=/cgi-bin/*.cgi
 
  cgipat=/cgi-bin/*.cgi
 
  charset=utf-8
 
  charset=utf-8
 +
 +
Change your configuration accordingly, and run
 +
 +
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
 +
/etc/init.d/thttpd2 restart
  
 
== Redirection ==
 
== Redirection ==
  
<strong>You cannot redirect index.html with thttpd!!!</strong>
+
<strong>You can't redirect index.html with thttpd; but you can redirect "dirname/".</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.  
 
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
 
  cd /mnt/share/www # this is our server root
  mv community.html 2>/tmp/ # make sure there's no offending file
+
  mv community.html /tmp/ # make sure there's no offending file
 
  ln -s cgi-bin/redirect.cgi community.html
 
  ln -s cgi-bin/redirect.cgi community.html
 
  echo '/community.html http://linkstationwiki.net' >> cgi-bin/.redirects
 
  echo '/community.html http://linkstationwiki.net' >> cgi-bin/.redirects
Line 55: Line 58:
  
 
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.
 
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.
 
http://hvkls.dyndns.org/downloads/documentation/ makes heavy use of the technique described here.
 
  
 
  cd /mnt/share/www # this is our server root
 
  cd /mnt/share/www # this is our server root
 
  mkdir docs
 
  mkdir docs
 
  cd docs
 
  cd docs
  echo '&lt;!--#echo var="LAST_MODIFIED" --&gt;' > mod.txt # create the file
+
  echo '&lt;!--#echo var="LAST_MODIFIED" --&gt;' > mod.txt # create new!! file
 
  mv mod.txt ../ssi/mod.shtml
 
  mv mod.txt ../ssi/mod.shtml
 
  ln -s ../cgi-bin/redirect.cgi mod.txt
 
  ln -s ../cgi-bin/redirect.cgi mod.txt
Line 67: Line 68:
  
 
See "man ssi" for details and more variables, how to include files, and more about SSIs.  
 
See "man ssi" for details and more variables, how to include files, and more about SSIs.  
 +
 +
Hint: Use "virtual" instead of "file" if you want to include files, giving the path relative to the server root.
  
 
[[Category:General]]
 
[[Category:General]]
 
[[Category:Howto]]
 
[[Category:Howto]]
 +
[[Category:Debian]]
 +
 +
[[Category:Software]]

Latest revision as of 12:47, 10 October 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. You might also find Articles/GeneralThttpdSSL useful for your web server.

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.

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

Change your configuration accordingly, and run

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
/etc/init.d/thttpd2 restart

Redirection

You can't redirect index.html with thttpd; but you can redirect "dirname/".

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 /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 new!! 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.

Hint: Use "virtual" instead of "file" if you want to include files, giving the path relative to the server root.