How do you use https / SSL on localhost?

134,763

Solution 1

If you have IIS Express (with Visual Studio):

To enable the SSL within IIS Express, you have to just set “SSL Enabled = true” in the project properties window.

See the steps and pictures at this code project.

IIS Express will generate a certificate for you (you'll be prompted for it, etc.). Note that depending on configuration the site may still automatically start with the URL rather than the SSL URL. You can see the SSL URL - note the port number and replace it in your browser address bar, you should be able to get in and test.

From there you can right click on your project, click property pages, then start options and assign the start URL - put the new https with the new port (usually 44301 - notice the similarity to port 443) and your project will start correctly from then on.

enter image description here

Solution 2

It is easy to create a self-signed certificate, import it, and bind it to your website.

1.) Create a self-signed certificate:

Run the following 4 commands, one at a time, from an elevated Command Prompt:

cd C:\Program Files (x86)\Windows Kits\8.1\bin\x64

makecert -r -n "CN=localhost" -b 01/01/2000 -e 01/01/2099 -eku 1.3.6.1.5.5.7.3.3 -sv localhost.pvk localhost.cer

cert2spc localhost.cer localhost.spc

pvk2pfx -pvk localhost.pvk -spc localhost.spc -pfx localhost.pfx

2.) Import certificate to Trusted Root Certification Authorities store:

start --> run --> mmc.exe --> Certificates plugin --> "Trusted Root Certification Authorities" --> Certificates

Right-click Certificates --> All Tasks --> Import Find your "localhost" Certificate at C:\Program Files (x86)\Windows Kits\8.1\bin\x64\

3.) Bind certificate to website:

start --> (IIS) Manager --> Click on your Server --> Click on Sites --> Click on your top level site --> Bindings

Add or edit a binding for https and select the SSL certificate called "localhost".

4.) Import Certificate to Chrome:

Chrome Settings --> Manage Certificates --> Import .pfx certificate from C:\certificates\ folder

Test Certificate by opening Chrome and navigating to https://localhost/

Solution 3

This question is really old, but I came across this page when I was looking for the easiest and quickest way to do this. Using Webpack is much simpler:

install webpack-dev-server

npm i -g webpack-dev-server

start webpack-dev-server with https

webpack-dev-server --https
Share:
134,763
HShbib
Author by

HShbib

.NET Developer

Updated on March 26, 2020

Comments

  • HShbib
    HShbib about 4 years

    I would like to know how to setup SSL on my web application on the localhost.

    I have no background in doing this, would appreaciate guidance. I already finished implementing my web application and i need it to use https on the localhost or while I host it on a server.

    Any Ideas?

    Regards.

  • Admin
    Admin about 8 years
    How do you get the files you just used in command makecert? localhost.pvk localhost.cer cert2spc localhost.cer localhost.spc . How do i get the private.key file to make a allinone.pem file to use in other web-servers then IIS?
  • user1944491
    user1944491 over 6 years
    This will serve the js files that make up the application, but does not run the application.
  • The Red Pea
    The Red Pea about 5 years
    Can I choose the port? i.e. use the default https port ; port 443?
  • Hashim Aziz
    Hashim Aziz over 4 years
    Can this be used alongside an existing dev server like XAMPP?
  • JackArbiter
    JackArbiter about 4 years
    @TheRedPea In every case I have encountered you need to use port 44301 to test locally in lieu of using port 443. This will not affect the ports you use for your live server (which you bind in IIS), which will almost always be 443 assuming you are using https.
  • Jason Williams
    Jason Williams about 4 years
    If you do not want to import the certificate into Chrome, you may opt to disable the Chrome security feature which blocks access to self-signed certs on localhost stackoverflow.com/a/31900210/2733283