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 siteDefaults.logFile.directory -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 = $site.name
$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 {$_.id} | 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"