Next.js Localhost https Setup

This will be a short one but it is really useful for anyone that needs https setup on localhost or better yet with a custom domain.


We need local-ssl-proxy which is a simple SSL HTTP proxy using a self-signed certificate.

npm install -g local-ssl-proxy

Install certificate generation utilities locally:

brew install mkcert nss
mkcert --install


Normally if we want to make localhost run on https, we simply run the following command in the project root directory:

mkcert localhost

However if you'd like to run on a custom domain of your choice because your API server has special requirements that demand running on specific domain:


This should generate and in the same directory.

In your package.json,

"scripts": {
  "dev": "next dev -p 3400 & local-ssl-proxy --key --cert --source 443 --target 3400"

This will start the Next.js server and the proxy concurrently or you can simply use concurrently.

Edit your /etc/hosts file by adding this line so your computer knows points to localhost.

Now running npm run dev and navigating to should see your app running.

If you find this useful please share it on Twitter and let me know on twitter.