Lighttpd, a lightweight web server, is renowned for its speed, security, and flexibility. Configuring Lighttpd to use a specific port is a common task, as it allows you to run multiple web servers on the same system. By default, Lighttpd listens on port 80 for HTTP and 443 for HTTPS. However, you might want to change these to other ports for various reasons, such as running multiple web servers or complying with specific network policies.

In this guide, we'll walk you through the process of configuring Lighttpd to use a different port. We'll cover both the configuration file method and the command-line method for your convenience.

Configuring Lighttpd Port via Configuration File
Modifying the Lighttpd configuration file is the most reliable and recommended method to change the port. This method ensures that the changes persist even after server restarts.

Here's a step-by-step guide to configuring Lighttpd port via the configuration file:
Accessing the Configuration File

First, you need to locate the Lighttpd configuration file. By default, it's located at `/etc/lighttpd/lighttpd.conf`. You can use a text editor like nano or vim to open the file:
$ sudo nano /etc/lighttpd/lighttpd.conf
Modifying the Port Settings
Once you're in the configuration file, look for the following lines:

server.port = 80 server.https.port = 443
To change the ports, simply replace the numbers with your desired ports. For example, to use ports 8080 for HTTP and 8443 for HTTPS, change the lines to:
server.port = 8080 server.https.port = 8443
After making the changes, save and close the file. Then, restart Lighttpd to apply the new settings:
$ sudo /etc/init.d/lighttpd restart
Configuring Lighttpd Port via Command Line

For quick changes or testing purposes, you can configure Lighttpd port directly from the command line. This method is convenient but does not persist across server restarts.
Here's how to configure Lighttpd port via the command line:




















Using the lighttpd -f Option
The `-f` option allows you to specify a configuration file to use. You can create a temporary configuration file with your desired port settings and pass it to Lighttpd:
$ sudo lighttpd -f /path/to/your/configfile.conf
Using the lighttpd -p Option
The `-p` option lets you specify the port directly from the command line. This is useful for quick tests:
$ sudo lighttpd -p 8080
To use this method, you'll need to run the command each time you start Lighttpd. For persistent changes, use the configuration file method.
In conclusion, configuring Lighttpd to use a different port is a straightforward process. Whether you choose to modify the configuration file or use the command line, you can easily run Lighttpd on your desired port. Always remember to restart Lighttpd after making changes, and ensure that the port you choose is not already in use by another service. Happy configuring!