Changing default listening port of lighttpd in Raspberry Pi OS no longer honors external.conf

Hello, I'm using the latest, current Raspberry Pi OS lite 64bit, for my Pihole install.

/etc/debian_version says 11.6, and all my packages are up to date with a "sudo apt update; sudo apt-get dist-upgrade". What's the version of the debian package of lighttpd, you ask? 1.4.59-1+deb11u2

After reading past, locked threads like this one, I tried to change the default listening port from 80 to 8080. But when I create /etc/lighttpd/external.conf, containing:

server.port := 8080

...it just gets ignored when I "sudo systemctl restart lighttpd.service". An nmap to the ports of 80 and 8080 from an external machine confirms this.

So how did I get it to work? Instead of creating /etc/lighttpd/external.conf, I created (as root) /etc/lighttpd/conf-available/04-external.conf, containing that same line above. Then I created a symlink pointing to it as follows (as root):

cd /etc/lighttpd/conf-enabled
ln -s ../conf-available/04-external.conf 04-external
systemctl restart lighttpd.service

Then nmap, run from another machine, verified the new port of 8080 was used instead of the default of 80.

The behavior of external.conf was changed a few months ago.

There is a note on the Upgrade Notes: GitHub - pi-hole/docker-pi-hole: Pi-hole in a docker container (second item).

Also, there are some posts commenting the change, like this: External.conf not being loaded in 2023.1 - #2 by PromoFaux

Your solution is exactly the new recommend way to add changes to lighttpd. :+1:


Just a note:

Any files created directly in conf-enabled will work just like the symlink.

Creating the file in conf-available and adding a symlink to conf-enabled is the pattern used by lighttpd to allow enabling/disabling config files keeping the original files intact (you simply create a symlink to enable a config and unlink to disable it).

1 Like

Completely new here...pls correct if I commented improperly. The solution did not work for me until the enabled file had .conf, e.g., ln -s ../conf-available/04-external.conf 04-external.conf

For Debian derivatives, you can use lighty-enable-mod and lighty-disable-mod to do the symlinking for you:

pi@ph5b:~ $ cat /etc/lighttpd/conf-available/README
ligghttpd Configuration under Debian GNU/Linux
==============================================

Files and Directories in /etc/lighttpd:
---------------------------------------

lighttpd.conf:
         main configuration file

conf-available/
        This directory contains a series of .conf files. These files contain
        configuration directives necessary to load and run webserver modules.
        If you want to create your own files they names should be
        build as nn-name.conf where "nn" is two digit number (number
        is used to find order for loading files)

conf-enabled/
        To actually enable a module for lighttpd, it is necessary to create a
        symlink in this directory to the .conf file in conf-available/.

Enabling and disabling modules could be done by provided
/usr/sbin/lighty-enable-mod and /usr/sbin/lighty-disable-mod scripts.
pi@ph5b:~ $ dpkg -S /usr/sbin/lighty-enable-mod
lighttpd: /usr/sbin/lighty-enable-mod

Checkout:

man lighty-enable-mod

EDIT: Ow you have similar for apache2:

$ man a2enconf
[..]
NAME
       a2enconf,  a2disconf  -  enable or disable an apache2 configuration file

This script should solve your issue.

You can enter the new port number when the script prompts you to enter it or you can pass the new port number as the first argument and it will automatically change the port without needing to enter anything else.

GitHub Bash Script

@SlyFox1186 , you're not suppose to alter /etc/lighttpd/lighttpd.conf !

pi@ph5a:~ $ cat /etc/lighttpd/lighttpd.conf
[..]
###################################################################################################
#   IF THIS HEADER EXISTS, THE FILE WILL BE OVERWRITTEN BY PI-HOLE'S UPDATE PROCEDURE.            #
#   ANY CHANGES MADE TO THIS FILE WILL BE LOST ON THE NEXT UPDATE UNLESS YOU REMOVE THIS HEADER   #
#                                                                                                 #
#   ENSURE THAT YOU DO NOT REMOVE THE REQUIRED LINE:                                              #
#                                                                                                 #
#   include "/etc/lighttpd/conf-enabled/*.conf"                                                   #
#                                                                                                 #
###################################################################################################

Thats amongst others what this thread is about.

The script also installs UFW which might not be desired!
And I have no clue why you involve apache2 in the script?

I would not recommend running this script by others!

Well I'm sorry you feel like this was not what you were looking for. I love this script. It does exactly what I want it to do.
Side note: Apache2 is included in the code in case you have it installed also running a browser or server of some type that also takes up precious ports. It is meant to alive any crossover ports issues that would cause the changes made to the lighttpd file not work.

Thanks for strong arming my post. I will make sure that I ask Jesus if I got everything right for 100% of the people on the internet before I post the next thing I think might help somebody.

And just so you know, I looked at your code and reworked my script to be more like your method and as far as I can tell it works flawlessly. So here's to you damn it.

I hope you didnt copy too much of my stuff bc I'm a n00b at coding Bash ... damn it back at you :wink:
But I know it can be difficult to code a "one size fits all" solution and have all bases covered.
I didnt want to discourage you and hope you'll continue exploring Bash etc!

This is only true if you are updating older installations.
To be more precise, if you (in the past) installed Pi-hole v5.14.2 (or a prior version) and kept updating the same installation, you shouldn't touch lighttpd.conf.

On the other hand, the new versions (v5.15+) use different config files.
This new config tries to use the default lighttpd.conf (or installs a very similar one if the user didn't have a previous file), without the header you posted above.
In this case, the port can be changed in lighttpd.conf or using a custom file in /etc/lighttpd/conf-enabled.

2 Likes

That what I meant with "have all bases covered" :wink:

1 Like