I cannot create a proper deployment package for AWS Elastic Beanstalk to enable gzip compression on Windows IIS environments.
我无法为AWS Elastic Beanstalk创建适当的部署包以在Windows IIS环境中启用gzip压缩。
I enabled in web config as described here. This worked only for static files, dynamic files are served as is.
我启用了web配置,如此处所述。这仅适用于静态文件,动态文件按原样提供。
Anybody have a solution for this?
有人有解决方案吗?
Edit: There is another issue with IIS. It doesn't compress files requested from proxies and also serves the original file on the first request. This causes CDN's to serve uncompressed file because their endpoints caches the original file.
编辑:IIS还有另一个问题。它不会压缩从代理请求的文件,也会在第一次请求时提供原始文件。这会导致CDN提供未压缩的文件,因为它们的端点会缓存原始文件。
2 个解决方案
#1
After struggling 10 hours finally I came up with a solid solution.
经过10个小时的努力,我终于想出了一个坚实的解决方案。
AWS supports config files to modify the environment. They run before deploying application. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
AWS支持配置文件以修改环境。它们在部署应用程序之前运行。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
So I created a config file to enable gzip on IIS, placed it to ".ebextensions/gzip.config" in my project folder.
所以我创建了一个配置文件来在IIS上启用gzip,将它放在我的项目文件夹中的“.ebextensions / gzip.config”中。
Configuration in YAML format:
以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
There are some changes needed in web.config to system.webServer section:
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>
With this two changes Elastic Beanstalk instances are prepared to serve compressed static and dynamic files. Also works with CDN.
通过这两个更改,Elastic Beanstalk实例准备好提供压缩的静态和动态文件。也适用于CDN。
#2
- If you don't have the compression roles setup see '00' below
-
If your applicationHost.config disables changes in web.config:
如果您的applicationHost.config禁用web.config中的更改:
<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
I found it easiest to supplement the existing applicationHost.config dynamicTypes using '05''s below.
我发现使用下面的'05'补充现有的applicationHost.config dynamicTypes是最容易的。
如果您没有压缩角色设置,请参阅下面的“00”
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
#1
After struggling 10 hours finally I came up with a solid solution.
经过10个小时的努力,我终于想出了一个坚实的解决方案。
AWS supports config files to modify the environment. They run before deploying application. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
AWS支持配置文件以修改环境。它们在部署应用程序之前运行。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
So I created a config file to enable gzip on IIS, placed it to ".ebextensions/gzip.config" in my project folder.
所以我创建了一个配置文件来在IIS上启用gzip,将它放在我的项目文件夹中的“.ebextensions / gzip.config”中。
Configuration in YAML format:
以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
There are some changes needed in web.config to system.webServer section:
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>
With this two changes Elastic Beanstalk instances are prepared to serve compressed static and dynamic files. Also works with CDN.
通过这两个更改,Elastic Beanstalk实例准备好提供压缩的静态和动态文件。也适用于CDN。
#2
- If you don't have the compression roles setup see '00' below
-
If your applicationHost.config disables changes in web.config:
如果您的applicationHost.config禁用web.config中的更改:
<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
I found it easiest to supplement the existing applicationHost.config dynamicTypes using '05''s below.
我发现使用下面的'05'补充现有的applicationHost.config dynamicTypes是最容易的。
如果您没有压缩角色设置,请参阅下面的“00”
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