Gzip compression on IIS - Can't get it to work - iis

I have an existing IIS application, and I am trying to get GZIP server side compression to work. The application runs on EPIServer CMS (which I am not that familiar with) - Thinking this could be related to the CMS somehow, as a first step...
I decided to create a new IIS application and this time using Umbraco (another CMS that I am very familiar with) - I have created a basic page with some CSS files and images,
Content-Encoding: gzip
header.
This is what I have tried and checked.
Working locally, I am running windows 10. and IIS 10
I have enabled Dyamic Content Compression and Static Content Compression under Internet Information Services > Performance Features in Windows Features
For the locally set up website in IIS I have ensured that the compression section has both Enable Dynamic & Static check boxes are ticked.
In my web-config file I have added this single line
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false" />
When the Webconfig has this line I inspect the headers in my browser:
REQUEST HEADERS
Accept: text/css,*/*;q=0.1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Host: umbracotest.site
Proxy-Connection: keep-alive
Referer: http://umbracotest.site/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36
RESPONSE HEADERS
Accept-Ranges: bytes
Content-Type: text/css
Date: Tue, 01 May 2018 15:09:02 GMT
ETag: "03739d0e978d31:0"
Last-Modified: Tue, 19 Dec 2017 16:52:54 GMT
Transfer-Encoding: chunked
Vary: Accept-Encoding
If I change that webconfig line slightly - dynamicCompressionBeforeCache="false" to true - then I just get a whole bunch of symbols in the browser - does that mean anything?
If I add a few more lines in to my webconfig to look like this:
<system.webServer>
<httpCompression>
<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="image/jpeg" enabled="true" />
<add mimeType="image/png" enabled="true" />
<add mimeType="image/svg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"
dynamicCompressionLevel="8" />
</httpCompression>
<urlCompression doDynamicCompression="true" doStaticCompression="true"
dynamicCompressionBeforeCache="false" />
headers are still the same.
C:\inetpub\temp\IIS Temporary Compressed Files\MYAPPPOOL-NAME << this folder is created but empty.
This is a ASP.net MVC application
Any ideas?

So after banging my head on the wall for about 8 hours, I finally got it to work!
After checking everything twice, reading every post I could find on the topic, I came across a comment to a similar question that suggested it could be something to do with my antivirus software. I'm working in an enterprise environment and I don't have the rights to disable it on my local machine. So I deployed the code to our staging server......... and it works.
So in case someone else has this problem, try and disable your anti-virus and see if that makes any difference, it worked for me.

Related

GZip compression not working on Windows Server 2016

I have the dynamic GZip module installed, and the relevant settings set in IIS, but when I test my images, each site I use tells me GZip is not installed.
ASP.net v4.6
Windows Server 2016
IIS 10.0
Request header:
Host: [redacted]
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Cookie: [redacted]
Upgrade-Insecure-Requests: 1
If-Modified-Since: Mon, 16 Sep 2019 15:23:43 GMT
If-None-Match: "b5b591b9a26cd51:0"
Cache-Control: max-age=0
TE: Trailers
Response header:
HTTP/2.0 200 OK
content-type: image/x-icon
last-modified: Wed, 06 Sep 2017 09:19:33 GMT
accept-ranges: bytes
etag: "87b86540f126d31:0"
server: Microsoft-IIS/10.0
x-powered-by: ASP.NET
date: Thu, 31 Oct 2019 00:45:49 GMT
content-length: 1150
X-Firefox-Spdy: h2
IIS setting:
Web.config:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" dynamicCompressionDisableCpuUsage="90" dynamicCompressionEnableCpuUsage="0">
<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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<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="image/png" 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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<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="image/png" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
GZip test:
FREB helped me identify some settings in my web.config were problematic. I cleared out all the configuration and did it via IIS and GZIP is now working.

Reverse proxy IIS returning 403 for OPTIONS request

I set up a reverse proxy to be able to call SSRS behind our firewall. It's mostly working but I'm stuck trying to solve the pre-flight OPTIONS request that keeps getting a 403. Am I missing anymore configuration changes? I've seen other post where people were returning a 200 for OPTIONS request. Can that be done from a reverse proxy?
web.config (for reverse proxy)
<?xml version="1.0" encoding="UTF-8"?><configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<security>
<authorization>
<add accessType="Allow" users="*" verbs="GET,POST,PUT,OPTIONS" />
</authorization>
<requestFiltering>
<verbs applyToWebDAV="false">
<add verb="OPTIONS" allowed="true" />
</verbs>
</requestFiltering>
</security>
<handlers> <remove name="OPTIONSVerbHandler" />
<add name="MyOPTIONSVerbHandler" path="*" verb="OPTIONS" modules="StaticFileModule" requireAccess="None" />
</handlers><httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Request-Headers" value="Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization, Access-Control-Allow-Origin,Access-Control-Request-Headers,Access-Control-Allow-Credentials" />
<add name="Access-Control-Request-Methods" value="GET, PUT, POST, DELETE, HEAD, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization, Access-Control-Allow-Origin,Access-Control-Request-Headers,Access-Control-Allow-Credentials" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD, OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Max-Age" value="1728000" />
</customHeaders> </httpProtocol>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://my-ssrs-url/{R:1}" />
<serverVariables>
<set name="HTTP_Authorization" value="Basic {omitted}" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer></configuration>
Chrome Headers:
Request URL:http://my-reverseproxy-url:8088/reports/api/v1.0/CatalogItems(86f0591c-8eb5-4951-9ca3-d16a847d6dd6)/Model.DataSet/Model.GetData?maxRows=
Request Method:OPTIONS
Status Code:403 Forbidden
Remote Address:172.20.32.200:8088
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization, Access-Control-Allow-Origin,Access-Control-Request-Headers,Access-Control-Allow-Credentials
Access-Control-Allow-Methods:GET, PUT, POST, DELETE, HEAD, OPTIONS
Access-Control-Allow-Origin:*
Access-Control-Max-Age:1728000
Access-Control-Request-Headers:Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization, Access-Control-Allow-Origin,Access-Control-Request-Headers,Access-Control-Allow-Credentials
Access-Control-Request-Methods:GET, PUT, POST, DELETE, HEAD, OPTIONS
Cache-Control:private
Content-Length:0
Date:Tue, 16 May 2017 16:58:53 GMT
Server:Microsoft-IIS/8.5
Set-Cookie:XSRF-NONCE=QxQVNGHrnygkOO5pESdPWSX7gD7N9IkyDFZeb8SSZeI%3D; path=/reports; HttpOnly
Set-Cookie:XSRF-TOKEN=voBxCxC7FAtwDnRDx%2B4tQ0UfBThZFcmq2cF0nwCbtKK%2FB6%2FI4TFt8lDA9OXmNABaAD4tKL2ygGnvp1MkucOgTqDlN3khUOaV8f2LbFWuMthkjOoH%2BcCXRWrmnx9akYOmRdPRyIB9Kxjq9Lz0px1%2BME6NtYvNnyxhUlnaczusO8k5wLNvo8OqTFB751b%2Fqm9E; path=/reports
X-Content-Type-Options:nosniff
X-Powered-By:ASP.NET
X-Powered-By:ARR/3.0
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:content-type,x-xsrf-token
Access-Control-Request-Method:POST
Connection:keep-alive
Host:my-reverseproxy-url:8088
Origin:http://my-ssrs-url
Referer:http://my-ssrs-url/reports/api/v1.0/SafeGetSystemResourceContent(type='mobilereportruntime',key='web')?v=3.9.118
User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Query String Parameters
view source
view URL encoded
maxRows:
Chrome Console:
OPTIONS http://my-reverseproxy-url:8088/reports/api/v1.0/CatalogItems(86f0591c-8eb5-4951-9ca3-d16a847d6dd6)/Model.DataSet/Model.GetData?maxRows= 403 (Forbidden)
XMLHttpRequest cannot load http://my-reverseproxy-url:8088/reports/api/v1.0/CatalogItems(86f0591c-8eb5-4951-9ca3-d16a847d6dd6)/Model.DataSet/Model.GetData?maxRows=. Response for preflight has invalid HTTP status code 403

Gzip not working, server 2012, IIS 8

Problems with activating Gzip on IIS 8 on a windows server 2012 (standard)
So i activated the compressions in the windows features
I checked both checkboxes in IIS - compression (dynamic and static)
But still no Gzip available.
However, on my localhost machine (just a windows 10) this works.
What i do see, is that the gzip temp directory (C:\inetpub\temp\IIS Temporary Compressed Files) is getting filled up when i browse my site via the server localhost. BUT strangely enough i'm not seeing anything Gzip-ped in chrome.
The only headers (in chrome) are:
HTTP/1.1 304 Not Modified
Accept-Ranges: bytes
ETag: "0a354779de8d11:0"
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Date: Thu, 28 Jul 2016 13:41:04 GMT
(Even yslow is saying no gzip is activated)
When i remove the gzip temp folder, and browse to the site trough the 'official' website url, then nothing is even generated.
Does anyone has any idea what is going on here?
//edit:
Even added this in the web.config
<httpCompression>
<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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" />
</httpCompression>
Here's how I would troubleshoot this:
I'm using PowerShell here, but you could use the GUI or other tools as well:
Make sure you have the failed request tracing module installed:
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
enable the tracing for your site (change the name):
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[#name='Default Web Site']/traceFailedRequestsLogging" -name "enabled" -value "True"
Setup tracing:
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -filter "system.webServer/tracing/traceFailedRequests" -name "." -value #{path='*.html'}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -filter "system.webServer/tracing/traceFailedRequests/add[#path='*.html']/traceAreas" -name "." -value #{provider='WWW Server';areas='Compression';verbosity='Verbose'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -filter "system.webServer/tracing/traceFailedRequests/add[#path='*.html']/failureDefinitions" -name "statusCodes" -value "200,304"
you end up with something like this in your web.config:
<system.webServer>
<tracing>
<traceFailedRequests>
<add path="*.html">
<traceAreas>
<add provider="WWW Server" areas="Compression" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200,304" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
I limited it to html files with a http status of 200 or 304 and we are only interested in Compression. You may want to change that.
Now you can hit your site a few times and then look in
C:\inetpub\logs\FailedReqLogFiles\W3SVCx
for some files, copy them to your workstation, because it's a pain to open them on the server.
Open the XML files and click on the Request Details tab, now search for Compression you should see details about the compression process or a reason why the request wasn't compress, like NOT_FREQUENTLY_HIT or TOO SMALL

Gzip not working - NO_MATCHING_SCHEME

Problems with activating Gzip on IIS 8 on a windows server 2012 (standard)
So i activated the compressions in the windows features
I checked both checkboxes in IIS - compression (dynamic and static)
But still no Gzip available. However, on my localhost machine (just a windows 10) this works.
What i do see, is that the gzip temp directory (C:\inetpub\temp\IIS Temporary Compressed Files) is getting filled up when i browse my site via the server localhost. BUT strangely enough i'm not seeing anything Gzip-ped in chrome.
The only headers (in chrome) are: HTTP/1.1 304 Not Modified Accept-Ranges: bytes ETag: "0a354779de8d11:0" Server: Microsoft-IIS/8.0 X-Powered-By: ASP.NET Date: Thu, 28 Jul 2016 13:41:04 GMT
(Even yslow is saying no gzip is activated)
When i remove the gzip temp folder, and browse to the site trough the 'official' website url, then nothing is even generated.
Does anyone has any idea what is going on here?
I added this in my web.config
<httpCompression>
<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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<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="image/jpeg" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" />
</httpCompression>
See this other topic, where i activated more log information, Gzip not working, server 2012, IIS 8
All i get is:
<RenderingInfo Culture="nl-BE">
<Opcode>STATIC_COMPRESSION_NOT_SUCCESS</Opcode>
<Keywords>
<Keyword>Compression</Keyword>
</Keywords>
<freb:Description Data="Reason">NO_MATCHING_SCHEME</freb:Description>
</RenderingInfo>
Can you try adding this to your web.config file ?? I suggest so because it worked for me on IIS windows shared hosting. Its similar to your code with a few changes...
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<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/javascript; charset=utf-8" enabled="true"/>
<add mimeType="application/x-javascript" 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/javascript; charset=utf-8" enabled="true"/>
<add mimeType="application/x-javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>
I'm not sure if you need to add
<add mimeType="image/jpeg" enabled="true" />
Isn't jpeg a compressed format ? You could add it none the less if you wish to.
[OPTIONAL]: I read this at MaxCdn.
Origin servers should include Vary: Accept-Encoding, and here’s how:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Vary"></remove>
<add name="Vary" value="Accept-Encoding"></add>
</customHeaders>
</httpProtocol>
</system.webServer>
You can add this bit to your web.config file as well, deploy and check it in the request headers through your browser's developer tools itself.

IIS 7.5 and images not being cached

I cannot get the image files to cache. I have tried everything that I have found on this site and others and still cannot get them to cache.
Web config setting that I have tried
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<httpProtocol allowKeepAlive="true" />
<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".png" policy="CacheUntilChange" />
<add extension=".jpg" policy="CacheForTimePeriod" duration="12:00:00" />
</profiles>
</caching>
Here is the response headers for 1 of the images
Key Value
Response HTTP/1.1 200 OK
Cache-Control no-cache
Content-Type image/png
Last-Modified Thu, 16 Dec 2004 18:33:28 GMT
Accept-Ranges bytes
ETag "a1ca4bc9de3c41:0"
Server Microsoft-IIS/7.5
X-Powered-By ASP.NET
Date Fri, 18 May 2012 13:21:21 GMT
Content-Length 775
The following should cause the browsers to cache your images:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
The <caching>...</caching> block is for server-side caching, not client side caching.
In case anyone needs to configure your site as Chrome Audits or GTMetrix require I've configured my environments with the following (thanks to Marco's answer):
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
using 365 days and both tools took that value as acceptable for a cache time.

Resources