@denis
To run a Next.js app over HTTPS in production mode, you will need to set up a secure HTTPS server and configure your Next.js app to use it. Here are the steps to accomplish this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
const fs = require('fs'); const https = require('https'); const next = require('next'); const dev = process.env.NODE_ENV !== 'production'; const app = next({ dev }); const handle = app.getRequestHandler(); app.prepare().then(() => { https .createServer( { key: fs.readFileSync('/path/to/private.key'), cert: fs.readFileSync('/path/to/certificate.crt'), }, (req, res) => { handle(req, res); } ) .listen(443, (err) => { if (err) throw err; console.log('> Ready on https://localhost:443'); }); }); |
1
|
node server.js |
Your Next.js app should now be running over HTTPS in production mode. Make sure to configure your server to handle HTTPS requests properly and redirect HTTP requests to HTTPS to ensure a secure connection.