Created
June 20, 2021 21:06
-
-
Save karmanyaahm/d7de678d51a33b71df6ec1df18f80d51 to your computer and use it in GitHub Desktop.
Caddy IPNS mount server custom 404 page and response code for other situations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
auto_https disable_redirects | |
} | |
(upgrade) { | |
@upgradable { | |
header Upgrade-Insecure-Requests 1 | |
protocol http | |
} | |
redir @upgradable https://{host}{uri} 308 | |
} | |
# replace :1111 with whatever host ur using | |
:1111 { | |
import upgrade | |
root * /ipns/{host} | |
file_server { | |
index index.html | |
} | |
handle_errors { | |
@404 expression {http.error.status_code} == 404 | |
handle @404 { | |
rewrite * /404.html | |
file_server | |
# 404 file doesn't exist | |
@no not file /404.html | |
respond @no "{http.error.status_code} {http.error.status_text}" | |
} | |
@other expression {http.error.status_code} != 404 | |
handle @other { | |
respond "{http.error.status_code} {http.error.status_text}" | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment