简体   繁体   中英

Adding site and bindings (with Host Name, Port, and IP Address) to IIS with appcmd

I am trying to use appcmd.exe to add a website to IIS.

I have almost everything working except one small bug.

The line of code I am using is

add site /name:WEBSITENAME /bindings:https://HOSTNAME:10.100.213.121:443 /physicalpath:C:\inetpub\WEBSITENAME

When I do this and look at the bindings on IIS it has everything correct except my ip address is shown to be "*:10.100.213.121" (excluding the quotes)

somewhere it is adding the *: to the beginning of it.

This is creating an invalid binding.

I want to keep this to only one command

I know I can use a second command to edit site bindings, but if i can keep this all the the creation of the site that would be ideal

Perhaps a syntactical issue with your bindings parameter to take note of which also indicates an answer to the question:

According to the reference documentation The bindings parameter can be passed in the following format:

/bindings:http/*:85: -- note single slash after protocol

Your example indicates the following format was used.

/bindings:http//*:85: -- note the extra forward slash after the protocol.

Hence:

OPTION 1

Perform the task as a single command:

 appcmd add site /name:WEBSITENAME /physicalpath:C:\inetpub\WEBSITENAME /bindings:https/10.100.213.121:443:

OPTION 2

Perform the task as a two phase commit.

  1. creates the site (a variation of what you already have minus the binding info)

  2. applies the binding configuration change required.

The reason for the two phase commit in this example is due to the second command requiring a site to exist prior to the configuration change being applied.

NOTE: The two commands are separated with & on the command line so they can be run as a single line.

appcmd add site /name:WEBSITENAME /physicalpath:C:\inetpub\WEBSITENAME & appcmd.exe set config  -section:system.applicationHost/sites /+"[name='WEBSITENAME'].bindings.[protocol='https',bindingInformation='10.100.213.121:443:']" /commit:apphost

Additional Documentation

I tested it now as follows and it worked.

appcmd add site /name:test.com /physicalPath:C:\inetpub\wwwroot\test.com /bindings:http/192.168.0.1:80:test.com

I hope this helps you.

see below how I used to SSL port 443

appcmd set site /site.name: NAME_SITE_IIS /+bindings.[protocol='https',bindingInformation='*: 443:yourdomain.com.br ']

Where it is in bold , change the information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM