How to disable vary User-Agent from response header in Apache - apache

I have tried a few .htaccess commands like RequestHeader unset User-Agent
but it isn't working. I also removed compression to check whether it was trigerring User-Agent or not but it wasn't.
Could you tell me how to remove Vary User-Agent from my response header. I think it is there by default.
Might it be that it has to be done from cPanel & WHM. If that is the case then could you guide me on how to do it?
Or if it is to be done through .htaccess then also I need your help on how to do it.
Here's how my .htaccess currently looks like:
# ------------------------------------------------------------------------------
# | Web fonts access |
# ------------------------------------------------------------------------------
# Allow access from all domains for web fonts
<IfModule mod_headers.c>
<FilesMatch "\.(eot|otf|ttc|ttf|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
# ------------------------------------------------------------------------------
# | Compression |
# ------------------------------------------------------------------------------
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-eot
AddOutputFilterByType DEFLATE application/x-font-woff
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/woff
AddOutputFilterByType DEFLATE font/eot
AddOutputFilterByType DEFLATE font/svg
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
# ------------------------------------------------------------------------------
# | Add Expiry and Unset Pragma and ETag |
# ------------------------------------------------------------------------------
Header unset Pragma
# 1 Month for most static assets 3 months for proxies
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|swf)(\.gz)?$">
Header set Cache-Control "max-age=2592000, s-maxage=7776000, must-revalidate, proxy-revalidate, no-transform"
Header unset ETag
FileETag None
</FilesMatch>
# 3 Days for normal and 1 week for proxies
<filesMatch ".(css|xml|html|php)$">
Header set Cache-Control "max-age=259200, s-maxage=604800, must-revalidate, proxy-revalidate, no-transform"
Header unset ETag
FileETag None
</FilesMatch>
#-------------------------------------------------------------------------------
Any help would be greatly appreciated. Thanks in advance!

Related

Elastic Bean Stalk support for compression - Apache in Amazon Linux 2 machines

We are planning to move from X86 environment environment to arm based environment and in the process we wanted to test Graviton instance - c7g
I am trying to implement gzip compression in Apache using the following steps.
SetOutputFilter DEFLATE
SetEnv force-gzip true
DeflateCompressionLevel 9
DeflateMemLevel 9
DeflateWindowSize 1
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
Also made sure the modules mod_filter and mod_deflate is enabled. Per Amazon documentation, https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html
Does this means we can't use gzip compression even at Apache level
Kindly confirm

gzip compression is not working using MEAN STACK and LiteSpeed Server with cPanel access - mod deflate; mod gzip

I've been trying to compress my files using gzip but it's not working. I have tested the website on several gzip test sites and some says my website is gzipped but www.giftofspeed.com/gzip-test/ says otherwise and my website
This is what I currently have in my .htaccess file (not the root file but I have a similar one):
> RewriteEngine On
> # If an existing asset or directory is requested go to it as it is RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond
> %{DOCUMENT_ROOT}%{REQUEST_URI} -d RewriteRule ^ - [L] RewriteCond
> %{REQUEST_METHOD} OPTIONS RewriteRule ^(.*)$ $1 [R=200,L]
>
> # If the requested resource doesn't exist, use index.html RewriteRule ^ /index.html
>
> <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$"> Header set
> Cache-Control "max-age=2628000, public" </filesMatch>
>
> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*"
> Header always set Access-Control-Allow-Methods "OPTIONS, POST, GET,
> DELETE, PUT, PATCH" Header always set Access-Control-Max-Age "86400"
> Header always set Access-Control-Allow-Headers
> "append,delete,entries,foreach,get,has,keys,set,values,
> x-requested-with, Content-Type, origin, authorization, accept,
> client-security-token, x-auth-token"
> # Header always set Content-Length: totalBytes
> # Header always set Content-Encoding: gzip </IfModule>
>
> <IfModule mod_mime.c> AddType application/x-javascript .js AddType
> text/css .css </IfModule> <IfModule mod_deflate.c> SetOutputFilter
> DEFLATE <IfModule mod_setenvif.c> SetEnvIfNoCase Request_URI
> \.(?:rar|zip)$ no-gzip dont-vary SetEnvIfNoCase Request_URI
> \.(?:gif|jpg|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI
> \.(?:avi|mov|mp4)$ no-gzip dont-vary SetEnvIfNoCase Request_URI
> \.mp3$ no-gzip dont-vary </IfModule> <IfModule mod_headers.c>
> Header append Vary User-Agent env=!dont-vary </IfModule> </IfModule>
>
> <IfModule mod_deflate.c> <FilesMatch
> "\\.(html|php|txt|xml|js|css|htm|jpg|png|jpeg|woff|woff2)$">
> SetOutputFilter DEFLATE </FilesMatch> </IfModule>
>
>
> <IfModule mod_deflate.c> # Compress HTML, CSS, JavaScript, Text, XML
> and fonts AddOutputFilterByType DEFLATE application/javascript
> AddOutputFilterByType DEFLATE application/rss+xml
> AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
> AddOutputFilterByType DEFLATE application/x-font
> AddOutputFilterByType DEFLATE application/x-font-opentype
> AddOutputFilterByType DEFLATE application/x-font-otf
> AddOutputFilterByType DEFLATE application/x-font-truetype
> AddOutputFilterByType DEFLATE application/x-font-ttf
> AddOutputFilterByType DEFLATE application/x-font-woff
> AddOutputFilterByType DEFLATE application/x-font-woff2
> AddOutputFilterByType DEFLATE application/x-javascript
> AddOutputFilterByType DEFLATE application/xhtml+xml
> AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType
> DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf
> AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE
> font/woff AddOutputFilterByType DEFLATE font/woff2
> AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType
> DEFLATE image/x-icon AddOutputFilterByType DEFLATE image/jpeg
> AddOutputFilterByType DEFLATE image/png AddOutputFilterByType
> DEFLATE image/gif AddOutputFilterByType DEFLATE image/bmp
> AddOutputFilterByType DEFLATE image/jpeg, AddOutputFilterByType
> DEFLATE text/css AddOutputFilterByType DEFLATE text/html
> AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType
> DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml
>
> # Remove browser bugs (only needed for really old browsers)
> BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch
> ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip
> !gzip-only-text/html Header append Vary User-Agent
>
> </IfModule>
>
> # compress text, html, javascript, css, xml: # Compress HTML, CSS, JavaScript, Text, XML and fonts AddOutputFilterByType DEFLATE
> application/javascript AddOutputFilterByType DEFLATE
> application/rss+xml AddOutputFilterByType DEFLATE
> application/vnd.ms-fontobject AddOutputFilterByType DEFLATE
> application/x-font AddOutputFilterByType DEFLATE
> application/x-font-opentype AddOutputFilterByType DEFLATE
> application/x-font-otf AddOutputFilterByType DEFLATE
> application/x-font-truetype AddOutputFilterByType DEFLATE
> application/x-font-ttf AddOutputFilterByType DEFLATE
> application/x-font-woff AddOutputFilterByType DEFLATE
> application/x-font-woff2 AddOutputFilterByType DEFLATE
> application/x-javascript AddOutputFilterByType DEFLATE
> application/xhtml+xml AddOutputFilterByType DEFLATE application/xml
> AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType
> DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf
> AddOutputFilterByType DEFLATE font/woff AddOutputFilterByType
> DEFLATE font/woff2 AddOutputFilterByType DEFLATE image/svg+xml
> AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType
> DEFLATE image/jpeg AddOutputFilterByType DEFLATE image/png
> AddOutputFilterByType DEFLATE image/gif AddOutputFilterByType
> DEFLATE image/bmp AddOutputFilterByType DEFLATE image/jpeg,
> AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE
> text/html AddOutputFilterByType DEFLATE text/javascript
> AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType
> DEFLATE text/xml
>
> # Remove browser bugs (only needed for really old browsers)
> BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch
> ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip
> !gzip-only-text/html Header append Vary User-Agent
>
> # Or, compress certain file types by extension: <files *.html> SetOutputFilter DEFLATE </files>
> # php -- BEGIN cPanel-generated handler, do not edit
> # Set the “ea-php74” package as the default “PHP” programming language. <IfModule mime_module> AddHandler
> application/x-httpd-ea-php74 .php .php7 .phtml </IfModule>
> # php -- END cPanel-generated handler, do not edit
I am currently using cPanel. Server is Litespeed. I have enabled zlib.output.compression found in MultiPHP INI Editor; also selected "Compress All Content" in Compress All Content. I have pretty much tried every solution I can possibly find online but gzip is still not working. I have also contacted my provider and they wanted me to check my code/script but I know my code works because it works locally and on another web hosting provider's site. The issue only arouse after I have changed it to this provider.

Gzip compression is not working even if it's enabled on the server

I have installed php7 with apache2 modules :-
I have also tested php.ini file, it also shows gzip:enabled
Then I have enable GZIP Compression via .htaccess source: https://gtmetrix.com/enable-gzip-compression.html
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
But Gzip Compression is stil not working
Try add this mod_gzip conf in .htaccess, maybe it help:
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>

Apache gzip SOAP

I am new to Apache and I am trying to figure out how to enable gzip compression to send data over to clients (.NET Compact Framework devices).
I am using Apache 2.2 and so far, I have enabled mod_deflate.so but my content send over netwrok is not gzipped.
Any idea? much appreciated
UPDATE
I am on Windows using Apache 2.2. In my httpd.conf file, I uncommented this line.
LoadModule deflate_module modules/mod_deflate.so
My module Location is in httpd.conf file like this:
<Location /MyModule>
SetHandler mod_MyModule-handler
</Location>
And in httpd.conf file, I already had all this, so nothing was changed here except that I have uncommented DeflateCompressionLevel 9:
<Location />
# Insert filter
SetOutputFilter DEFLATE
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/x-javascript
#DeflateCompressionLevel 9 //if I uncomment this, server wont start
# 1 to 9: 9 is the most compressed
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
#The following statement indicate which document types not to compress. Many type of documents do not compress well.
#At the end (Appendix 1) of this article some more type you might wish to also exclude from compression
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
# install/enable the Apache module mod_headers
Header append Vary User-Agent env=!dont-vary
# install/enable the Apache module LoadModule expires_module modules/mod_expires.so
# turn on the module for this directory
ExpiresActive on
# set defaults
ExpiresByType text/javascript "modification plus 11 months"
ExpiresByType application/javascript "modification plus 11 months"
ExpiresByType text/css "modification plus 11 months"
</Location>
Then I restart Apache, send request to it and receive response but response.ContentEncoding does not show "gzip" in .NETCF client. It looks like I am missing something.
uncomment the deflate module
LoadModule deflate_module modules/mod_deflate.so
and add this stanza to the virts config like this (be sure to include your soap mime type)
<IfModule deflate_module>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
bash test
function check_compression {
curl -s -k -I -H 'Accept-Encoding: gzip,deflate' $1 |grep "Content-Encoding"
}
check_compression http://your.url.com
If that doesn't work, check that you have the mime type set correctly for the soap response.

Am I overkilling my htaccess with all of these cache expiry

I want to make sure I am not over killing my website with all of these htaccess. Can you tell me what is unnecessary or what I am missing?
I added things to improve my gtmetrix score every time it complained and it slowly fixed a lot of issues. But now I have a giant list that I have a feeling could be reduced or optimized somehow
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
</IfModule>
# 1 WEEK
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 2 HOURS
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
You are not overkilling your apache with Cache parameters.
However some areas like Worker Configuration, removing unwanted modules, Log Level, Keep Alive, HostNameLookup can help you to improve further.
One of the other thing which you can explore if you can have Caching Server like Varnish in front of Apache which would help to reduce Apache overhead and faster response time