Serving static files with lighttpd

From WeBWorK_wiki
Revision as of 15:22, 27 August 2011 by Aubreyja (talk | contribs)
Jump to navigation Jump to search

WeBWorK servers experiencing high loads may optionally install the lightweight webserver lighttpd to serve static files. According to the lighttpd documentation,

lighttpd is a secure, fast, compliant, and very flexible web-server that has been optimized for high-performance environments. It has a very low memory footprint compared to other webservers and takes care of cpu-load. Its advanced feature-set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more) make lighttpd the perfect webserver-software for every server that suffers load problems.[1]

Installation of lighttpd may be done at any time and your active courses will continue to function seemingly without change. The only change behind the scenes will be that static images and pages will be served by a light weight web server. However, installation of lighttpd as described here does come with one caution: the default security settings of some web browsers and some university firewall configurations have been reported to block images served through a different port than port 80. See below.

Installation and configuration

Install lighttpd

You must first install lighttpd according to the instructions for your operating system. Installation packages are available for Ubuntu and Debian, Red Hat and Fedora, openSUSE, Gentoo, and a FreeBSD port of httpd is also available. Links to those packages and installation instructions are available in the lighttpd installation documentation.

Configure lighttpd

Most linux distributions will place the lighttpd.conf configuration file with the other configuration files in /etc at /etc/lighttpd.conf or /etc/lighttpd/lighttpd.conf.On FreeBSD, the configuration file is at /usr/local/etc/lighttpd.conf. Open this file for editing as root.

Since Apache is listening on port 80 so we need an alternate port for lighttp to listen on. Standard alternate ports for this are usually 81, 8000, or 8080. 8080 is the only port that is listed as official alternate[2].

Find the server.port line

# server.port               = 81

and uncomment it and change 81 to 8080 so that it reads

server.port               = 8080

If you would like to be able to view lighttpd server status information on the web, then uncomment the line

#           "mod_status",

so that it becomes

            "mod_status",

and uncomment the line

# status.status-url = "/server-status"

so it becomes

status.status-url = "/server-status"

The default settings for the other configuration parameters in lighttpd.conf should work fine for our purposes. If you find that the default settings for other lighttpd configuration parameters produce errors are are not suitable, please report the issue in the WeBWorK forum, and see the official lighttpd configuration instructions for further reference.

After making your changes to httpd.conf save the file, quit the editor, and restart lighttpd. On linux, this can typically be done by running this command as root:

/etc/init.d/lighttpd start

Note that the command /etc/init.d/lighttpd with no arguments will list all of the options for the lighttpd executable.

Now test your server by connecting to "http://localhost:8080/" and/or connecting to your server from a browser on a remote machine. You should see the page It works! indicating that lighttp is running.

If you enabled mod_status, then you can check lighttp's status by connecting to "http://localhost:8080/server-status" using a browser on your machine or from to "http://yourserver.yourschool.edu:8080/server-status" from a browser on a remote machine.

Configure WeBWorK to use lighttpd

To configure WeBWorK to use lighttpd, we must change two values in global.conf: $webworkURLs{htdocs_temp} and $courseURLS{html_temp}. To do so, as root open global.conf for editing. If your $webworkURLs{htdocs_temp} and $courseURLS{html_temp} are set with their default values from global.conf.dist then find the line

$webworkURLs{htdocs_temp}   = "$webworkURLs{htdocs}/tmp";

and replace it by

#$webworkURLs{htdocs_temp}   = "$webworkURLS{htdocs}/tmp";
$webworkURLs{htdocs_temp}   = "$webworkURLS{htdocs}:8080/tmp';

and find the line

$courseURLs{html_temp}   = "$courseURLs{html}/tmp";

and replace it by

#$courseURLs{html_temp}   = "$coursesURLs{html}/tmp";
$courseURLs{html_temp}   = "$coursesURLs{html}:8080/tmp";

If you have set up WeBWorK to store it's temporary files on a separate partition, then find the line

$webworkURLs{htdocs_temp}   = '/wwtmp'

and replace it by

#$webworkURLs{htdocs_temp}   = '/wwtmp';
$webworkURLs{htdocs_temp}   = 'http://yourserver.yourschool.edu:8080/wwtmp';

and find the line

$courseURLs{html_temp}   = "/wwtmp/$courseName";

and replace it by

#$courseURLs{html_temp}   = "/wwtmp/$courseName";
$courseURLs{html_temp}   = "http://yourserver.yourschool.edu:8080/wwtmp/$courseName";

then save the file and quit.

Now restart apache and lighttp. As root or with sudo restart apache and lighttpd. For example, on Ubuntu this would be done with

 $ sudo apache2ctl graceful
  password:<wwadmin password>
 $ sudo /etc/init.d/lighttpd restart

To test things go to a course, e.g. http://yourserver.yourschool.edu/webwork2/myTestCourse/. Before you login right click on the WeBWorK icon in the upper left hand corner of the login page. The click on Properties (or whatever is appropriate on your browser) and check that the image is being served from port 8080 (something like http://yourserver.yourschool.edu:8080/webwork2_files/images/webwork_rectangle.png. Then log into your course and view a problem with typeset equations (e.g. Problem 1 of the Demo set). Again right click on the typeset equation and check that the image is being served from port 8080.

Potential problems

Two problems have been reported from this set up.

First, in some cases, a firewall configuration may block httpd requests to port 8080. If this is due to the firewall set up on the WeBWorK server itself, then it should not be difficult to fix by consulting the documentation for the operating system of the server. If this is due to the firewall set up at your institution, then resolving this issue will require cooperation from the IT group there.

Second, the default security settings on some browsers (notably MSIE) may cause the browser to issue a warning alert every time a WeBWorK problem containing an image is accessed. This can be terribly annoying to users of MSIE. Such users should be encouraged to use a better web browser or to change the security settings of their preferred browser.

If you find that one of these issues cannot be resolved, you can easily disable lighttpd for WeBWorK by undoing the changes to global.conf made above.

Forum discussions

External links

References