Merge pull request #295 from anoop-b/caddy-2

Added documentation on caddy-2
This commit is contained in:
Adam Warner
2020-05-14 15:47:55 +01:00
committed by GitHub
+37 -3
View File
@@ -2,6 +2,8 @@
If you'd like to use [Caddy](https://caddyserver.com/) as your main web server with Pi-hole, you'll need to make a few changes.
> Note: This guide only deals with setting up caddy as a reverse-proxy and not as a replacement for lighttpd (Although caddy is capable of doing so, but it is beyond the scope of this guide).
## Modifying lighttpd configuration
First, change the listen port in this file: `/etc/lighttpd/lighttpd.conf:`
@@ -28,6 +30,8 @@ sudo service lighttpd restart
Now set up a "virtual host" in your Caddyfile (default `/etc/caddy/Caddyfile`). There are many options you can add, but at a minimum, you need to make a "default" host by binding `0.0.0.0:80`. This will accept requests for any interface.
### Caddyfile (Caddy Version 1)
```
blackhole:80, pi.hole:80, 0.0.0.0:80 {
root /var/www/html/pihole
@@ -46,17 +50,45 @@ blackhole:80, pi.hole:80, 0.0.0.0:80 {
In this case, I've chosen to also add blackhole and pi.hole as valid names to open the admin page with.
Finally, restart your Caddy server: `sudo service caddy restart`
### Caddyfile (Caddy version 2)
```
pi.hole:80{
reverse_proxy localhost:1080
}
```
- If you'd like to enable Https on your site, make sure your server is reacheable via your domain name (ex: myawesomesite.com) and is pointing to the right IP address.
- Additionally you need to open ports :80 and :443 (Apart from the one's required specifically for pi-hole) for your server before setting up https.
The following configuration will automatically fetch and setup Https for your domain using Lets-Encrypt
```
myawesomesite.com {
reverse_proxy localhost:1080
}
```
Additionally you can make pihole reacheable via a subdomain and optionally can you enable Zstandard and Gzip compression as follows:
```
pihole.myawesomesite.com {
reverse_proxy localhost:1080
encode zstd gzip
}
```
Finally, run `sudo systemctl daemon-reload` to force caddy to load the new configuration.
## Verifying your setup
First, make sure that any other sites you're serving from caddy are still functioning. For example, if you have a block for `myawesomesite.com:80` in your Caddyfile, open up a browser to `http://myawesomesite.com` and verify it still loads.
First, make sure that any other sites you're serving from caddy are still functioning. For example, if you have a block for `myawesomesite.com:80` or similar in your Caddyfile, open up a browser to `http://myawesomesite.com` (or `https://` if you have enabled it) and verify it still loads.
Next, verify you can load the admin page. Open up `http://pi.hole/admin` (or use the IP address of your server) and verify that you can access the admin page.
Finally, verify that requests for ads are being black holed:
```bash
```console
$ curl -H "Host: badhost" pi.hole/
<html>
<head>
@@ -75,3 +107,5 @@ Lastly, ensure that requests for JavaScript files from advertisement domains are
curl -H "Host: badhost" pi.hole/malicious.js
var x = "Pi-hole: A black hole for Internet advertisements."
```
For more information visit caddy's documentation [website](https://caddyserver.com/docs/).