Lighttpd Mini-HOWTO: using different ports with same URL/IP address

PLEASE NOTE: Native Lighttpd Windows builds are available at http://en.wlmp-project.net/
The last available Lighttpd for Windows build that I created using Cygwin was Lighttpd for Windows 1.4.17.
Updated September 29, 2009.

Let’s say that you want to run one Lighttpd web server on two different ports. Port 80 for the production site and Port 81 for development.

1. Set your port for production use, either by leaving server.port
commented or set:
server.port = 80
AND
set your standard document root:
server.document-root = “/path/to/production/version”

2. Add these lines to your config:
$SERVER[“socket”] == “:81” {
server.document-root = “/path/to/testing/version”
}

3. Restart lighttpd.

4. Connect to http://hostname:81 or http://[your IP]:81 (http://192.168.1.1:81)

TROUBLESHOOTING TIPS:
If you still can’t connect, check your firewall settings. RedHat Enterprise Linux and Windows XP with Service Pack 2 are covered below.

For RedHat Enterprise Linux, do:
[root@localhost ~]# iptables -F
to flush all firewall rules as a test. Connecting to port 81 should not be a problem after that. A safer option is to just open up that port rather than dumping all your rules, if you are running a production box.

On Windows XP with SP2, go to Start->Settings->Control Panel->Windows Firewall. If ‘On’ is selected, click the ‘Exceptions’ tab at the top, and then click the ‘Add Port…’ button and type in 81. If you are using another firewall, do the equivalent for that firewall. Although I do not recommend it, you could turn off all firewalls momentarily to see if the config is set up properly, but that is very dangerous.

(This Mini-HOWTO inspired by the answer I provided here: http://forum.lighttpd.net/topic/958)