Redirect all HTTP requests to HTTPS with a 301

I want to configure redirection from http to https

In Nginx it looks like this:

In the documentation I found only this:

But as I understand it all depends on the parameter “X-Forwarded-Proto” and if it does not, then redirection will not be either.
The option in Nginx as I understand it does not depend on it, how to do the same in Caddy?

Caddy does this by default with Automatic HTTPS. You can just leave your site scheme-agnostic, e.g.: {

And Caddy will run a 301 Redirect listening on HTTP and serve the actual site on HTTPS.

To manually redirect, you’ll need to specify a definition for the HTTP version of your site, one way or another:

# Blanket redir for entire HTTP version of site {
  redir https://{host}{uri}
} {
# Combination, check for HTTP scheme and redirect, {
  redir {
    if {scheme} is http
    / https://{host}{uri}


In the latter, {scheme} is used to detect the protocol.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.