102

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.

3

3 Answers 3

29

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

2
  • Can I choose the port? i.e. use the default https port ; port 443? Commented May 10, 2019 at 1:36
  • 1
    @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. Commented Mar 8, 2020 at 11:20
26

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/

3
  • 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?
    – user285594
    Commented Apr 7, 2016 at 9:40
  • 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 Commented Mar 25, 2020 at 18:25
  • Why the code signing eku instead of server auth eku?
    – Reahreic
    Commented May 24, 2023 at 12:27
10

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
2
  • 2
    This will serve the js files that make up the application, but does not run the application.
    – Hoshi
    Commented Nov 26, 2017 at 14:28
  • Can this be used alongside an existing dev server like XAMPP? Commented Nov 12, 2019 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.