Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: HTTP -> HTTPS redirects on all site configs #26

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

Lemmmy
Copy link
Member

@Lemmmy Lemmmy commented Jan 16, 2024

This PR changes the default behavior for setting up HTTP to HTTPS redirects. Previously, the redirects would only be set up if Casket was managing the TLS (it qualifies for automatic HTTPS).

Background

The conventional advice for servers using their own certificates or tls self_signed was to set up a redirect rule manually, like so:

redir 301 {
  if {>X-Forwarded-Proto} is http
  /  https://{host}{uri}
}

This is fine for one-off deployments, but when doing this for many domains, it becomes more appropriate to use a template. So, one might try:

(tls-selfsigned) {
  tls self_signed

  redir 301 {
    if {>X-Forwarded-Proto} is http
    /  https://{host}{uri}
  }
}

example.com {
  import tls-selfsigned
}

However, if the site that imports the template already has a redirect rule for /, this configuration will conflict. Thus, the desire to change the default behavior.

Solution

With this PR, all sites that have TLS enabled in any way will have a redirect created on the HTTP port. This is potentially a breaking change; if a configuration already assumes that nothing would be bound on port 80. To disable this behavior, you can now opt-out of the redirect creation per-site (even if the site qualifies for automatic HTTPS like before):

https://example.com {
  tls self_signed {
    no_redirect # Disable the automatic HTTP -> HTTPS redirect
  }
}

@Lemmmy Lemmmy added the enhancement New feature or request label Jan 16, 2024
@Lemmmy Lemmmy merged commit 588ead0 into master Jan 18, 2024
1 check passed
@Lemmmy Lemmmy deleted the lemmmy/tls-redirect branch January 18, 2024 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants