Serving static files with lighttpd
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.
Contents
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} = '/wwtmp'; $webworkURLs{htdocs_temp} = 'http://yourserver.yourschool.edu:8080/wwtmp';
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"; have not set up WeBWorK to store it's temporary files on a separate partition
Find the line
$webworkURLs{htdocs_temp} = "$webworkURLs{htdocs}/tmp";
$courseURLs{html_temp} = "$courseURLs{html}/tmp";
$webworkURLs{htdocs_temp} = '/wwtmp'
and replace it by
#$webworkURLs{htdocs_temp} = '/wwtmp'; $webworkURLs{htdocs_temp} = 'http://yourserver.yourschool.edu:8080/wwtmp';
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 run,
apache2ctl graceful password:<wwadmin password> /etc/init.d/lighttpd restart
To test things go to your test course 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
Note that in rare cases an installation may block httpd requests to port 8080. If any of your students report that they can not see graphics, they will have to request that access to requests to port 8080 be allowed.
Forum discussions
- images will not load (off campus) 23 Aug 2011
- some students can't load images 10 Sept 2009
- images not displaying 9 Apr 2009
- installation questions
External links
References
[Category:Administrators] [Category:Installation]