letsencrypt-helper
letsencrypt-helper copied to clipboard
Instructions/code on how to redirect http to https would be helpful
Hi! This is a useful project, thanks!
Instructions/code on how to redirect http to https would be helpful especially given that this is for small pet projects. I've been able to apply it to my pet project and now I don't have this 301 https redirect. Googling gave me too many ways and it's interesting what would be the best way for spring-boot.
Ok, makes sense, thanks for feedback
I have made an app which redirects all http to https. You need to tell the WebServer to open the http port and that all traffic to this port should be redirected to another port. This is done by registering a redirecting Connector, eg like this lib does for Tomcat The Spring Security Redirect config looks like this for me:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) {
// other config
if (sslEnabled) {
http.portMapper(Customizer.withDefaults())
.requiresChannel(channels -> channels
.anyRequest().requiresSecure()
);
}
return http.build();
}
}
If you have non-default ports, so not 8080/8443 or 80/443, you would have to also configure the portMapper, that's why I included it here. It's created by default, so calling .portMapper(Customizer.withDefaults()) is not strictly necessary.