Lessons in this course (9)

2. Sites, bindings, applications and virtual directories

Basic★ Must knowLesson 2 of 9
powershell
Import-Module WebAdministration

New-Item -ItemType Directory C:\sites\shop -Force
New-WebAppPool -Name "ShopPool"
New-Website -Name "Shop" -PhysicalPath "C:\sites\shop" -ApplicationPool "ShopPool" -Port 80 -HostHeader "www.shop.com"
New-WebBinding -Name "Shop" -Protocol https -Port 443 -HostHeader "www.shop.com" -SslFlags 1      # 1 = SNI
New-WebApplication -Site "Shop" -Name "api" -PhysicalPath "C:\sites\shop-api" -ApplicationPool "ShopApiPool"
New-WebVirtualDirectory -Site "Shop" -Name "downloads" -PhysicalPath "D:\shared\downloads"
  • Binding = protocol + IP (or *) + port + host header. Several sites can share port 80/443 if host names differ.
  • SNI (Server Name Indication) lets many HTTPS sites with different certificates share one IP:443.
  • An application under a site (/api) can run in a different app pool and has its own web.config root for ASP.NET.
  • A virtual directory only maps a URL to a folder (no separate app/pool).
  • hosts file (C:\Windows\System32\drivers\etc\hosts) can map www.shop.com to 127.0.0.1 for local testing.