我無法爲AWS Elastic Beanstalk創建適當的部署包,以在Windows IIS環境中啓用gzip壓縮。在Amazon Elastic Beanstalk Windows環境中啓用gzip
我在網頁配置中啓用了here。這僅適用於靜態文件,動態文件按原樣提供。
有人有這個解決方案嗎?
編輯: IIS還存在另一個問題。它不壓縮從代理請求的文件,並在第一個請求中提供原始文件。這會導致CDN提供未壓縮的文件,因爲它們的端點緩存了原始文件。
我無法爲AWS Elastic Beanstalk創建適當的部署包,以在Windows IIS環境中啓用gzip壓縮。在Amazon Elastic Beanstalk Windows環境中啓用gzip
我在網頁配置中啓用了here。這僅適用於靜態文件,動態文件按原樣提供。
有人有這個解決方案嗎?
編輯: IIS還存在另一個問題。它不壓縮從代理請求的文件,並在第一個請求中提供原始文件。這會導致CDN提供未壓縮的文件,因爲它們的端點緩存了原始文件。
終於掙扎了10個小時後,我想出了一個可靠的解決方案。
AWS支持配置文件來修改環境。他們在部署應用程序之前運行。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
所以我創建了一個配置文件來啓用IIS上的gzip,將其放置在我的項目文件夾中的「.ebextensions/gzip.config」中。
配置在YAML格式:
container_commands:
00-server-config:
command: c:\windows\system32\inetsrv\appcmd set config /section:system.webServer/serverRuntime /frequentHitThreshold:1 /frequentHitTimePeriod:00:00:05
waitAfterCompletion: 0
01-server-config:
command: c:\windows\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /noCompressionForHttp10:False /noCompressionForProxies:False
waitAfterCompletion: 0
02-gzip-dynamic:
command: c:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True
waitAfterCompletion: 0
03_gzip_static:
command: c:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doStaticCompression:True
waitAfterCompletion: 0
04_restart_iis:
command: iisreset
waitAfterCompletion: 0
有在web.config中需要system.webServer節的一些變化:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" noCompressionForHttp10="false" noCompressionForProxies="false">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/x-javascript" enabled="true"/>
<add mimeType="application/json; charset=utf-8" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/x-javascript" enabled="true"/>
<add mimeType="application/atom+xml" enabled="true"/>
<add mimeType="application/xaml+xml" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<httpProtocol>
<customHeaders>
<remove name="Vary" />
<add name="Vary" value="Accept-Encoding" />
</customHeaders>
</httpProtocol>
有了這個兩個變化彈性魔豆實例準備提供壓縮靜態和動態文件。也適用於CDN。
如果您的applicationHost.config禁用在web.config中的變化:
<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
我發現最簡單的補充現有的applicationHost.config dynamicTypes使用下面的'05'。
commands:
00-install-comp:
command: powershell.exe -nologo -noprofile -command "& { Import-Module ServerManager; Add-WindowsFeature Web-Stat-Compression,Web-Dyn-Compression; }"
waitAfterCompletion: 0
01-server-config:
command: c:\windows\system32\inetsrv\appcmd set config /section:system.webServer/serverRuntime /frequentHitThreshold:1 /frequentHitTimePeriod:00:00:05
waitAfterCompletion: 0
02-server-config:
command: c:\windows\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /noCompressionForHttp10:False /noCompressionForProxies:False
waitAfterCompletion: 0
03-gzip-dynamic:
command: c:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True
waitAfterCompletion: 0
04_gzip_static:
command: c:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doStaticCompression:True
waitAfterCompletion: 0
05_gzip_dyn_type_1:
command: c:\windows\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost
waitAfterCompletion: 0
ignoreErrors: true
05_gzip_dyn_type_2:
command: c:\windows\system32\inetsrv\appcmd set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
waitAfterCompletion: 0
ignoreErrors: true
06_restart_iis:
command: iisreset
waitAfterCompletion: 0