Skip to content

Instantly share code, notes, and snippets.

@sahal
Last active February 10, 2026 19:45
Show Gist options
  • Select an option

  • Save sahal/d6876ec3ed6c920e058db67fe3a4c113 to your computer and use it in GitHub Desktop.

Select an option

Save sahal/d6876ec3ed6c920e058db67fe3a4c113 to your computer and use it in GitHub Desktop.
lighttpd redirect configuration moved to user home directory

notes

Software: lighttpd 1.4.79 on Debian 13

This could be used on other distros with some modification.

Not sure what the service names for lighttpd are in your particular distro. Also, www-data is the group in debian that runs the lighttpd daemon, it might be different in your particular distro.

Add redirects from users home directory

I want to be able to manage 302 or 301 redirects from my home directory rather than editing config files owned by root.

allow www-data group members to restart lighttpd without sudo password

# visudo /etc/sudoers.d/www-data-restart-lighttpd
%www-data <machine-hostname> = (root) NOPASSWD: /usr/bin/systemctl restart lighttpd.service
%www-data <machine-hostname> = (root) NOPASSWD: /usr/bin/systemctl stop lighttpd.service
%www-data <machine-hostname> = (root) NOPASSWD: /usr/bin/systemctl start lighttpd.service

Add your user to the www-data group

# usermod -a -G www-data <username>

Configure lighttpd to use your redirect config

root@who:/etc/lighttpd/conf-enabled# cat 01_<somefilename>.conf
$HTTP["host"] == "<hostname>" {
  # by default the redirects will be 301
  url.redirect-code = 302

  include "/home/<username>/lighttpd/redirects.conf"

  server.document-root = "/var/www/<custom-folder>"
}

Configure redirects

username@who:~/lighttpd$ pwd
/home/username/lighttpd
username@who:~/lighttpd$ cat redirects.conf
# <hostname> redirects
# https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_redirect#Examples
# ./restart.sh
# ./check.sh <slug>

url.redirect = (
  "^/slug1(/?)" => "https://example.com/slug1",
  "^/slug2(/?)" => "https://example.com/slug2",
  "^/slug3(/?)" => "https://example.com/slug3",

)

set permissions for redirects config

sudo chown <username>:www-data /home/<username>/lighttpd/redirects.conf
sudo chmod o=  /home/<username>/lighttpd/redirects.conf

Restart lighttpd

./restart.sh

Check redirects

./check.sh slug-name

todo

Create a simple script that takes over for user's default shell so that after ssh-ing into a machine the user is presented with prompts to update, restart, and check the redirects automatically. SaaS via SSH maybe...

#!/usr/bin/env bash
set -e
set -u
set -x
wget -O /dev/null \
--server-response \
--debug \
--quiet "http://pop.hs.vc/${1:-none}" 2>&1
#!/usr/bin/env bash
set -e
set -u
sudo /usr/bin/systemctl restart lighttpd.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment