Set up Grails with HTTPS on a local development server
Setting up Grails with HTTPS on a local development server gives your application an encrypted path that resembles production. It also creates a safe place to exercise secure cookies, CSRF protection, OAuth callbacks and browser security rules before code reaches a shared environment. The finished setup should use a trusted local certificate, an HTTPS-enabled Grails listener and commands another developer can repeat without guesswork.
A local certificate is most useful when it is trusted by the browser and command-line clients on your own machine. You should be able to open the application without dismissing a warning while still keeping the private key and certificate authority outside source control. This matters for teams in Sydney, Melbourne and Brisbane, where developers may move between Windows, macOS and Linux laptops while working on the same Grails application.
Start by confirming the Java and Grails versions supported by your project. Modern Grails releases expose SSL through Spring Boot-style configuration, while older releases can use a different property namespace. Check the release documentation and existing application.yml before adding settings, since a clean Grails project is easier to secure than a configuration file carrying unrelated local changes.
The quickest reliable route is to create a local certificate authority with mkcert, issue a certificate for localhost and 127.0.0.1, convert that certificate into a PKCS#12 keystore, and point Grails at it. No public domain or cloud-hosted development server is required, and the same workflow can later support a reverse proxy if one application needs several local services.
Choose a supported local toolchain
Begin with a JDK that your exact Grails release supports, then verify both tools before generating a project. A mismatch often appears later as an unsupported class-file error or a TLS provider failure, so resolving versions first prevents confusing symptoms.
java -version
grails --version
grails create-app secure-local-app
cd secure-local-app
The generated project is enough for this exercise; database configuration, authentication plugins and deployment-specific settings are not required. Keep the certificate in a separate local directory such as $HOME/.certs/grails-local, rather than mixing it with source files that every developer might commit.
The Grails learning resources can help you compare the project layout and command syntax across Grails versions. If the repository already contains application.yml, application-prod.yml or custom environment files, inspect them before choosing where to place the development-only values.
Create a trusted development certificate
mkcert creates a small local certificate authority and signs host-specific certificates for it. After mkcert -install has added its root certificate to the operating system trust store, browsers can treat the resulting local site as genuinely secure. This avoids weakening TLS checks simply to silence a warning.
Install mkcert using the package manager for your platform, then run:
mkcert -install
mkcert -key-file localhost-key.pem -cert-file localhost.pem localhost 127.0.0.1 ::1
The generated certificate should contain both DNS and IP subject alternative names. Those names matter: accessing https://127.0.0.1:8443 when the certificate covers only localhost produces a hostname mismatch.
If policy prevents mkcert, keytool can create a self-signed PKCS#12 keystore directly, but you must then import the certificate into each trusted store manually. Use Australian identity fields only as certificate metadata: for example, Sydney and New South Wales with country code AU. They do not replace the required localhost and IP subject alternative names.
Prepare a Java-compatible keystore
Tomcat, which Grails uses for its embedded server, normally reads its TLS material from a Java keystore. Convert the PEM key and certificate issued by mkcert into a password-protected PKCS#12 file, and include the local CA certificate in the chain.
openssl pkcs12 -export \
-out localhost.p12 \
-inkey localhost-key.pem \
-in localhost.pem \
-certfile "$(mkcert -CAROOT)/rootCA.pem" \
-name localhost
OpenSSL prompts for an export password. Use the same password in the Grails configuration; do not append it to the command, where it would be retained in shell history.
Place the keystore in the external certificate directory and inspect its contents:
mkdir -p "$HOME/.certs/grails-local"
mv localhost.p12 "$HOME/.certs/grails-local/localhost.p12"
keytool -list -v \
-keystore "$HOME/.certs/grails-local/localhost.p12" \
-storetype PKCS12
The listing should identify localhost as an alias and show both localhost and 127.0.0.1 among the subject alternative names. Delete the loose PEM key once the PKCS#12 file has been verified.
Configure Grails for an HTTPS listener
Modern Grails applications use the server.ssl.* settings inherited from Spring Boot. Keep environment-specific paths and passwords out of committed YAML, and pass them as environment variables resolved at startup.
server:
port: 8443
address: 127.0.0.1
ssl:
enabled: true
key-store: file:${GRAILS_SSL_KEY_STORE}
key-store-password: ${GRAILS_SSL_KEY_STORE_PASSWORD}
key-store-type: PKCS12
Set the keystore path and password before launching the application. This Bash example hides the password while it is typed:
export GRAILS_SSL_KEY_STORE="$HOME/.certs/grails-local/localhost.p12"
read -rsp "Keystore password: " GRAILS_SSL_KEY_STORE_PASSWORD
echo
export GRAILS_SSL_KEY_STORE_PASSWORD
In Windows PowerShell, assign the values through $env:GRAILS_SSL_KEY_STORE and $env:GRAILS_SSL_KEY_STORE_PASSWORD, or load them from a local secret store. Some older Grails releases document grails.server.ssl.* rather than server.ssl.*; use the namespace supported by that release and avoid combining both forms in one file.
Start the server and verify encryption
Start Grails with grails run-app, wait for the embedded Tomcat startup message, and open https://127.0.0.1:8443/ in the browser. The lock icon should appear without a certificate warning because the operating system already trusts the mkcert authority.
Use command-line clients to confirm that the certificate chain, hostname and response all work:
curl --cacert "$(mkcert -CAROOT)/rootCA.pem" https://127.0.0.1:8443/
openssl s_client -connect 127.0.0.1:8443 \
-servername localhost \
-CAfile "$(mkcert -CAROOT)/rootCA.pem"
The first command returns an HTTP status even if the root route is absent, while the second shows the negotiated protocol, cipher and certificate chain. An unknown-authority error means the client is not using the same root certificate; it does not necessarily mean the Grails server is faulty. Machines in Sydney and Melbourne switch between AEST and AEDT on national daylight-saving dates, while Brisbane remains on AEST, so storing CI timestamps in UTC will prevent confusion.
Use a local reverse proxy when needed
A reverse proxy is useful when another local service, administration dashboard or callback endpoint must share one HTTPS origin. It also mirrors production more closely because Grails can remain on plain HTTP on loopback while the proxy terminates TLS and forwards the request.
Caddy can provide a compact local configuration:
https://localhost {
tls internal
reverse_proxy 127.0.0.1:8080
}
Run Caddy and trust its generated local root, then change Grails to an HTTP-only loopback listener and remove the server.ssl block:
server:
port: 8080
address: 127.0.0.1
forward-headers-strategy: framework
The proxy supplies forwarded protocol and host headers. That matters for secure cookies, redirects and generated links because Grails must know that the browser used HTTPS. Do not expose an HTTP proxy and the direct HTTPS Grails listener on the same network interface; loopback binding keeps both paths predictable.
Keep development secure and repeatable
Store localhost.p12, PEM files and root-CA exports outside the repository. Add *.p12, *.jks, localhost-key.pem and localhost.pem to .gitignore as a second line of defence. Use a local password manager or operating-system secret store for the keystore password, and never copy a development key into a deployment image.
Diagnose failures by their message. PKCS12 parse error usually means the wrong file or type; password was incorrect means the environment variable and keystore do not match; a hostname error means the requested name is absent from the certificate; and an unknown-authority error means the browser or client does not trust the local CA. Keep certificate validation enabled rather than using curl -k or a trust-all Java client.
A public staging URL may use an Australian .com.au or .au domain, while hosting and development tools may charge in Australian dollars. Keep that public certificate lifecycle separate from the localhost certificate: use an automated certificate service for the public hostname and reserve the local certificate authority for development only.
Test with synthetic records rather than real customer information, particularly when working with data governed by the Privacy Act 1988 and the Australian Privacy Principles. Keep external development notes beside the team checklist, while making the project repository the source of truth for exact commands and version-specific settings.
Create the local certificate, export the Grails SSL variables, launch grails run-app, and verify the endpoint with both the browser and curl. When the valid certificate appears, publish the repeatable commands in the project README and make HTTPS the default path for the next local Grails feature.