How to use appcmd.exe to add a new binding for HTTPS

Remotec picture Remotec · Dec 28, 2016 · Viewed 12.9k times · Source

I have the following script that sets up my website...

%AppCmd% ADD SITE /name:%SiteName% /physicalPath:%SitePath% /bindings:http/*:80:%SiteName%
%AppCmd% SET SITE /site.name:%SiteName% /[path='/'].applicationPool:%SiteName%

What I would like to do now is to find out how to add an additional binding for HTTPS. Seen plenty of pages describing now to add a host header to an existing https binding but none that show actually how to add a new binding as you can do in the UI.

Note: I believe I need two bindings, one HTTP (port 80) and one HTTPS (port 443) as at present I need to have port 80 open as I use a redirect rule to swap people that hit the site on port 80 over onto 443. If there is a way I can avoid doing this and simply my bindings I'm all for it.

Answer

Ercan picture Ercan · Mar 16, 2017

You can add multiple bindings for http or https.

Open command line and set path

cd %windir%\system32\inetsrv

add first binding

appcmd set site "mysite.domain.com.tr" /bindings:"https://mysite.domain.com.tr:443"

add other bindings

appcmd set site /site.name:mysite.domain.com.tr /+bindings.[protocol='https',bindingInformation='*:443:mysite1.domain.com.tr']
appcmd set site /site.name:mysite.domain.com.tr /+bindings.[protocol='https',bindingInformation='*:443:mysite1.domain.com.tr']
appcmd set site /site.name:mysite.domain.com.tr /+bindings.[protocol='https',bindingInformation='*:443:mysite1.domain.com.tr']

And you can export web site config file as xml

%windir%\system32\inetsrv\appcmd list site "mysite.domain.com.tr" /config /xml > "C:\Users\Administrator\Desktop\backup\mysite.domain.com.tr.xml"