I have two main scripts in my package.json for running a Nuxt 3 application with SSL:
"scripts": { ..."dev:ssl": "cross-env NODE_TLS_REJECT_UNAUTHORISED=0 nuxt dev --https --ssl-cert ../cc/my_cert.crt --ssl-key ../cc/my_key.hr.pem --host XX.XXX.X.XX --port XXXX","start:ssl": "cross-env NODE_TLS_REJECT_UNAUTHORISED=0 node .output/server/index.mjs --https --ssl-cert ../cc/my_cert.crt --ssl-key ../cc/my_key.hr.pem --host XX.XXX.X.XX --port XXXX"}
When I run npm run dev:ssl
, the development server starts correctly using HTTPS and the app works without issues. However, when I attempt to start the app with npm run start:ssl
, I encounter the following console output:'Listening on http::\\[..]:$port'
Despite the application being hosted on HTTPS, it still defaults to HTTP and marks the connection as unsafe, preventing access to the web app. I have verified that the SSL certificate and key are valid.
To resolve the issue, I also tried configuring the server directly in the nuxt.config.ts file as shown below, but the outcome remains the same:
import fs from 'fs'export default defineNuxtConfig({// ... server: { host: 'XX.XXX.X.XX', port: XXXX, https: { key: fs.readFileSync('correct_path_to_key.pem'), cert: fs.readFileSync('correct_path_to_cert.crt') } }// ...});
My Question:
How can I correctly configure my Nuxt 3 application for production to use HTTPS on a custom host address?It’s my first time setting up a production environment for a Nuxt app, so I might be missing some critical steps. I would greatly appreciate any guidance or suggestions for configuring HTTPS in this setup.
Additional Details:
- I am using valid SSL certificates (confirmed)
- The dev:ssl script works perfectly, but the issue arises in production with the start:ssl script.
- The Nuxt app needs to be hosted on a custom IP address.
Thank you in advance for your help!