Logo

dev-resources.site

for different kinds of informations.

Prevent Caddy's automatic http-to-https redirect

Published at
1/29/2024
Categories
caddy
Author
tylerlwsmith
Categories
1 categories in total
caddy
open
Author
12 person written this
tylerlwsmith
open
Prevent Caddy's automatic http-to-https redirect

Occasionally while developing a web app locally, you need to build an isolated feature that requires https (such as a service worker). Using a self-signed certificate locally introduces the annoyance of Chrome returning an error every few hours that says Your connection is not private.

It would be nice to only deal with those self-signed https warnings when you absolutely needed to use https, then access the site warning-free via http the rest of the time. However, Caddy automatically adds an http-to-https redirect for all domain site addresses.

You can prevent the automatic redirection from http-to-https by listing both http and https addresses at the beginning of the site block:

http://mysite.test, https://mysite.test {
    # bind allows access to containers from host when
    # running Caddy in Docker.
    bind 0.0.0.0

    # Issue a self-signed certificate for development.
    tls internal

    respond "Hello, world! I am being accessed from {scheme}."
}
Enter fullscreen mode Exit fullscreen mode

Do not use this configuration in production. There are very few responsible reasons to serve an http version of your production site. Only use this configuration for development.

Alternatively, you can disable http-to-https redirects for all sites in your Caddyfile by adding the following block to the top of your Caddyfile (as seen in this GitHub issue):

{
    auto_https disable_redirects
}
Enter fullscreen mode Exit fullscreen mode

Don't run this configuration in production either.

Gotchas

When developing locally, you may need to add the domains to your system's hosts file if they aren't already there.

caddy Article's
30 articles in total
Favicon
Building and Deploying a New API (Part 3)
Favicon
I Built a CaddyFile Generator Tool in Just 8 Hours – Here’s How It Went
Favicon
Caddy
Favicon
Caddy
Favicon
How to Set Up n8n on DigitalOcean with Docker and Caddy
Favicon
Step-by-Step Guide to Hosting Your Website on a VPS Using Caddy Server and Cloudflare
Favicon
How to manage SSL Certs with Caddy
Favicon
Effortless Web Hosting with Caddy: A Beginner’s Guide
Favicon
Path-Based Reverse Proxying with Caddy
Favicon
Deploy firefox as container
Favicon
Switch from NGINX to Caddy
Favicon
Self Hosting with Tailscale and Caddy
Favicon
How to Dockerize an Angular App for Production
Favicon
Compute Caddy payload using Jinja2 with Ansible
Favicon
Using the same Caddyfile for both development and production
Favicon
Configuring Wildcard Subdomains: A Comparison of Nginx and Caddy
Favicon
No more self signed certificate warnings: HTTPS local development using Caddy 2 on macOS
Favicon
Prevent Caddy's automatic http-to-https redirect
Favicon
Routing multiple paths to a reverse proxy using Caddy
Favicon
Generating SSL certificates for SaaS customers without the hefty price tag
Favicon
Caddy Server - Basic Configuration
Favicon
Using Caddy for automatic SSL certificates with Cloudflare
Favicon
From ALB to Caddy - Our Wandering Path to Supporting Thousands of Domain Names
Favicon
Use hex.docs locally
Favicon
AWS Lightsail Container Services with Reverse Proxy
Favicon
TOP 5 Design-to-Code, Figma-to-Code Tools: FUNCTION12, Anima, and More
Favicon
Install Snipe-IT on Ubuntu 22.04 - HostnExtra
Favicon
Install Caddy on Ubuntu 22.04 - HostnExtra
Favicon
Caddy in Docker with common_log
Favicon
How to deploy Caddy on Tencent Cloud CVM

Featured ones: