How do I host a website alongside pi-hole

Expected Behaviour:

Hi everyone, my default lighttpd.conf works fine, but after installing it gets replaced by the one from pi-hole: lighttpd.conf.
It says that your own files should be located at:

# Add user chosen options held in external file
include_shell "cat external.conf 2>/dev/null"own 

Actual Behaviour:

  1. Starting with HTTPS:// blocks everything
  2. Cant reach my website at al, located at /var/www/html/
  3. replaced it with the original lighttpd.conf and I get that the FLT engine is offline

Debug Token:

---=== Your debug token is : dqrug3htaq Please make a note of it. ===---

Fixed the problem! Will make a guide at my site: https://darthkeizer.ddns.net

It can be closed!

Can you please help me out ? waiting for your guide

Ah sure, do you sill have your lighttpd.conf from before. Pi-Hole makes a backup. Could you check if you still have that one :)?

Yes i do have the backup located in the /etc/lighttpd/ . Its the file lighttpd.conf.orig

  1. So at the top replace server modules with the following:
server.modules = (
	"mod_access",
	"mod_accesslog",
	"mod_expire",
	"mod_compress",
	"mod_redirect",
	"mod_setenv",
	"mod_rewrite"
)
  1. And paste this at the bottom:
# Pihole custom shizzle
# Rewite js requests, must be out of $HTTP block due to bug #2526
url.rewrite = ( "^(?!/admin/).*\.js$"  => "pihole/index.js"   )
# If the URL does not start with /admin, then it is a query for an ad domain
$HTTP["url"] =~ "^(?!/admin)/.*" {
	# Create a response header for debugging using curl -I
	setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." )
}
  1. Then use the following commands:
$ sudo service lighttpd reload
$ sudo service lighttpd restart
  1. Make a crontab with

sudo crontab -e

And add the following, the first lighttpd.conf should be the one you just edited and it will replace the lighttpd.conf editied by the updater of pihole.

# Pi-hole: Update Pi-hole! Uncomment to enable auto update
30 2 * * 7 root    PATH="$PATH:/usr/local/bin/" pihole updatePihole
40 2 * * 7 sudo cp -f /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
45 2 * * 7 sudo service lighttpd reload
46 2 * * 7 sudo service lighttpd restart

Please be aware that this file is volatile and changes to it directly are subject to change and overwrite by the Pi-hole update and install process.

dschaper@nanopineo:/etc/lighttpd$ cat lighttpd.conf
# Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
# lighttpd config for Pi-hole
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.



###############################################################################
#     FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE INSTALL/UPDATE PROCEDURE.     #
# ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE #
#                                                                             #
#              CHANGES SHOULD BE MADE IN A SEPERATE CONFIG FILE:              #
#                         /etc/lighttpd/external.conf                         #
###############################################################################

I think it's much easier and future proof.
Keep lighttpd.conf unchanged and put the following lines in /etc/lighttpd/external.conf

$HTTP["host"] == "" {
# Undo Pi-hole Javascript Redirect
url.rewrite = ("^(?!.)..js$" => ".*.js")
# root website
server.document-root = "/var/www/html/"
}

In /etc/dnsmasq.d create the file 04-customRedirect.conf with the following line

addn-hosts=/etc/customRedirect.list

in this file.

In /etc create the file customRedirect.list with the following line

192.168.x.xxx

where 192.168.x.xxx is the IP address of the PiHole
More lines could be added in this file, like
www.google.com www.bing.com
but also redirections to a locale webserver

So, with this configuration I run 2 websites local: google ajax and code.jquery.com

This works conform documentation and will not be overwritten during an update.
See Docs Configuration - Lighttpd - lighty labs
and https://www.reddit.com/r/pihole/comments/469y55/redirect_domains_to_something_other_than_127001/
(message of -PromoFaux-)

2 Likes