I followed the tutorial below to create a https server https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server/
and the program runs without errors
Assuming you are using node.js, then http-server has -S
or --ssl
with -C
and -K
to enable https.
If this is meant for testing and you don't need a valid cert (which seems to be the case since you're using "localhost") you can use a "self-signed" cert, just make sure to configure nginx to point to those.
I could explain the details, but there's actually a great post about that on Digital Ocean community tutorials:
https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-in-ubuntu-16-04
just be sure to adapt the port (443) if you want to listen on 8000.
I use Caddyserver with config like this:
:443
tls self_signed
Well one quick way to do this is with ngrok.
It's really easy to use and only takes few secs to run. It is as simple as downloading your system version. Unzip and run ngrok.exe
. It will open a command line type of window. Make sure your Apache server or the one you use is running.
Then to only listen on an HTTPS tunnel endpoint run the following
ngrok http -bind-tls=true site.dev:80
or on whatever port you need https
to be installed.
Open browser and type https://localhost/myApp
you will see it works.
And if you type http://localhost/myApp
it also works.
Hope this is helpful to anyone for a fast solution.
You need to do two things:
Managed to do this on a macOS like so:
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "/private/tmp/certs/certname.cer"
I finally set up my create-react-app https dev server
the reason why I'm doing this is to test device motion API on a mobile device.
install mkcert https://github.com/FiloSottile/mkcert
brew install mkcert
mkcert -install
generate cert files.
mkcert -key-file ./.cert/key.pem -cert-file ./.cert/cert.pem "<LAN_IP_ADDRESS>"
use LAN IP address instead of "localhost", because we will open our https page on a mobile device that has connected to the same WiFi.
create a .env
file to set env variables
HTTPS=true
SSL_CRT_FILE=./.cert/cert.pem
SSL_KEY_FILE=./.cert/key.pem
start the dev server
npm start
last but not least, install the cert file on the mobile device, the .pem
file generated by mkcert
is located in ~/Library/Application Support/mkcert
in my case.
install cert file on an Android device
https://support.google.com/pixelphone/answer/2844832?hl=en
install cert file on an iOS device
serve the .pem
file on a static server, and open the file address on Safari