How can I use an SSL certificate with my Next JS deployment?
Asked Answered
F

3

5

I have a Next.js deployment on an EC2 instance. I want to install an SSL certificate. The only way I can think of is to use a custom server config, but this seems to remove certain optimizations that I'd rather keep. Keep in mind I am starting the server using 'next start'.

The solutions I found online only apply to local deployments and they also involve using a custom server config.

Thanks

Fayfayal answered 23/3, 2022 at 6:33 Comment(1)
Based on existing answers it looks like you need to a) run the nextjs app on port 3000 (or some other port, just not 443) b) use a web server like apache or nginx to handle SSL c) proxy the requests to your nextjs serverNorma
S
1

an option is to use nginx and host configs

https://medium.com/today-i-solved/how-to-deploy-next-js-on-aws-ec2-with-ssl-https-7980ec6fe8d3

Signor answered 2/9, 2022 at 16:24 Comment(1)
how can we do it without using nginx ? Is it possible to configure ssl in nodejs where the application is deployed ?Frazzle
T
7

One of the quickest solutions is to:

  1. Dockerize Next.js application
  2. Set up a Docker Compose environment with two containers: the Next.js application itself and NGINX (the image is available on DockerHub to it's a matter of pulling it)
  3. Configure NGINX as a reverse proxy that handles the SSL part

With this approach, the question becomes a duplicate of this other SO. Details and code examples (in particular for the third point) are available there.

Tishatishri answered 24/2, 2023 at 8:23 Comment(0)
S
1

an option is to use nginx and host configs

https://medium.com/today-i-solved/how-to-deploy-next-js-on-aws-ec2-with-ssl-https-7980ec6fe8d3

Signor answered 2/9, 2022 at 16:24 Comment(1)
how can we do it without using nginx ? Is it possible to configure ssl in nodejs where the application is deployed ?Frazzle
K
0

As of the latest version of Next.js, this is now supported through next dev --experimental-https.

Ketchum answered 6/1 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.