6.29.5 Enabling HTTP and HTTPS
Micronaut supports binding both HTTP and HTTPS. To enable dual protocol support, modify your configuration. For example with application.yml
:
Dual Protocol Configuration Example
micronaut:
ssl:
enabled: true
build-self-signed: true (1)
server:
dual-protocol : true (2)
1 | You must configure SSL for HTTPS to work. In this example we are just using a self-signed certificate, but see Securing the Server with HTTPS for other configurations |
2 | Enabling both HTTP and HTTPS is an opt-in feature - setting the dualProtocol flag enables it. By default Micronaut only enables one |
It is also possible to redirect automatically all HTTP request to HTTPS. Besides the previous configuration, you need to enable this option. For example, with application.yml
:
Enable HTTP to HTTPS Redirects
micronaut:
ssl:
enabled: true
build-self-signed: true
server:
dual-protocol : true
http-to-https-redirect: true (1)
1 | Enable HTTP to HTTPS redirects |