How to create a https server on localhost

2019-03-09 12:57发布

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

but when I can not open https://localhost:8000 in my chrome

it always get a ERR_SSL_PROTOCOL_ERROR

enter image description here

4条回答
霸刀☆藐视天下
2楼-- · 2019-03-09 13:12

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.

查看更多
Emotional °昔
3楼-- · 2019-03-09 13:13

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.

查看更多
甜甜的少女心
4楼-- · 2019-03-09 13:19

I use Caddyserver with config like this:

:443
tls self_signed
查看更多
不美不萌又怎样
5楼-- · 2019-03-09 13:24

Assume you are using nodejs, then http-sever has -S or --ssl with -C & -K to enable https

查看更多
登录 后发表回答