Configuring IIS and IIS Websites

I’m new to Octopus and I’m trying to work out the best way to setup our webservers and websites in IIS.

Each of our webservers is configured with the following:

## Disable Directory Browsing
Set-WebConfigurationProperty 'system.webServer/defaultDocument' -PSPath IIS:\ -Name Enabled -Value "True"

# Setup Our Default Logging Options
Set-WebConfigurationProperty 'system.applicationHost/log' -PSPath IIS:\ -Name centralLogFileMode -Value "Site"
Set-WebConfigurationProperty 'system.applicationHost/sites' -PSPath IIS:\ -Name siteDefaults.logFile.enabled -Value "True"
Set-WebConfigurationProperty 'system.applicationHost/sites' -PSPath IIS:\ -Name siteDefaults.logFile.logFormat -Value "W3C"
Set-WebConfigurationProperty 'system.applicationHost/sites' -PSPath IIS:\ -Name siteDefaults.logFile.period -Value "Daily"
Set-WebConfigurationProperty 'system.applicationHost/sites' -PSPath IIS:\ -Name -Value "$BaseWebsitesDirectory\Logs"

# Turn on dynamic and static compression
Set-WebConfigurationProperty 'system.webServer/urlCompression' -PSPath IIS:\ -Name doDynamicCompression -Value "True"
Set-WebConfigurationProperty 'system.webServer/urlCompression' -PSPath IIS:\ -Name doStaticCompression -Value "True"

Remove-WebConfigurationProperty "system.webServer/httpCompression" -PSPath IIS:\ -Name "." -AtElement @{name='gzip'} -ErrorAction SilentlyContinue
Remove-WebConfigurationProperty "system.webServer/httpCompression" -PSPath IIS:\ -Name "." -AtElement @{name='deflate'} -ErrorAction SilentlyContinue
Add-WebConfigurationProperty "system.webServer/httpCompression" -PSPath IIS:\ -Name "." -Value @{name='deflate';dll='%Windir%\system32\inetsrv\gzip.dll';staticCompressionLevel=9;dynamicCompressionLevel=4}
Add-WebConfigurationProperty "system.webServer/httpCompression" -PSPath IIS:\ -Name "."  -Value @{name='gzip';dll='%Windir%\system32\inetsrv\gzip.dll';staticCompressionLevel=9;dynamicCompressionLevel=4}

Remove-WebConfigurationProperty "system.webServer/httpCompression/staticTypes" -PSPath IIS:\ -Name "." -AtElement @{mimeType='application/x-javascript';enabled='True'}
Remove-WebConfigurationProperty "system.webServer/httpCompression/dynamicTypes" -PSPath IIS:\ -Name "." -AtElement @{mimeType='application/json; charset=utf-8';enabled='True'}
Remove-WebConfigurationProperty "system.webServer/httpCompression/dynamicTypes" -PSPath IIS:\ -Name "." -AtElement @{mimeType='application/xml; charset=utf-8';enabled='True'}

Add-WebConfigurationProperty "system.webServer/httpCompression/staticTypes" -PSPath IIS:\ -Name "." -value @{mimeType='application/x-javascript';enabled='True'}
Add-WebConfigurationProperty "system.webServer/httpCompression/staticTypes" -PSPath IIS:\ -Name "." -value @{mimeType='image/svg+xml';enabled='True'}
Add-WebConfigurationProperty "system.webServer/httpCompression/dynamicTypes" -PSPath IIS:\ -Name "." -value @{mimeType='application/json; charset=utf-8';enabled='True'}
Add-WebConfigurationProperty "system.webServer/httpCompression/dynamicTypes" -PSPath IIS:\ -Name "." -value @{mimeType='application/xml; charset=utf-8';enabled='True'}

Each of our websites is configured with these settings:

$SiteName = $
$FQDN = $site.FQDN

# Create Website Directories
New-Item "$BaseWebsitesDirectory\Sites\$SiteName" -type Directory | Out-Null
New-Item "$BaseWebsitesDirectory\Logs\$SiteName" -type Directory | Out-Null

# Create An Application Pool
New-Item IIS:\AppPools\$SiteName -Force
$AppPool = Get-WebConfiguration "system.applicationHost/applicationPools/add[@name=`'$SiteName`']" -PSPath IIS:\
$AppPool.managedRuntimeVersion = "v4.0"
$AppPool.managedPipelineMode = "Integrated"
$AppPool.processModel.idleTimeout = "01:30:00"
$AppPool.recycling.periodicRestart.time = "00:00:00"
$AppPool.recycling.logEventOnRecycle = "Time,Requests,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory"
$AppPool.startMode = "AlwaysRunning"
$AppPool.autoStart = "True"
Set-WebConfiguration "system.applicationHost/applicationPools/add[@name='$SiteName']" -PSPath IIS:\ -Value $AppPool

## Work Around IIS bug
$id = (dir iis:\sites | foreach {$} | sort -Descending | select -first 1) + 1
# Create the Site
New-Item "IIS:\Sites\$SiteName" -PhysicalPath "$BaseWebsitesDirectory\Sites\$SiteName" -bindings @{protocol="http";bindingInformation=":80:$FQDN"} 

Set-ItemProperty IIS:\Sites\$SiteName -name applicationPool -value $SiteName

#Set Site Logging
Set-WebConfigurationProperty "system.applicationHost/sites/site[@name='$SiteName']/logFile" -PSPath IIS:\ -Name "directory" -Value "$BaseWebsitesDirectory\Logs\$SiteName"
Set-WebConfigurationProperty "system.applicationHost/sites/site[@name='$SiteName']/application[@path='/']" -PSPath IIS:\ -name "preloadEnabled" -value "True"

As far as I can see the deploy IIS task doesn’t really allow configuring these settings so I am assuming that a custom script will be required. What I’m wondering is where the script should run. Before or after the Deploy to IIS step?

Hi Jacob,

Thanks for getting in touch! You’re correct that the built-in IIS step doesn’t expose all IIS settings, and a custom script may be required. However we do have some step templates written by the community available on our library page. There are a lot of IIS-specific steps available which may help prevent so much custom scripting.

During the execution of the built-in IIS step, Octopus reconfigures everything to match the configuration defined in your deployment process, so your custom script should be run after the IIS step. :slight_smile:

I’m sorry it’s probably not the news you were after! I hope this helps though, and please don’t hesitate to reach out if you have any further questions moving forward.

Best regards,


I suppose it’s not exactly what I was hoping for but it’s not terrible either. I’m curious around your comments about it reconfiguring IIS each time. Is there any way of having it detect if the current website/app pool exist and if so skip the setup step?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.