How to disable the DEFLATE module for a specific directory? - apache

I am trying to figure out how to disable the DEFLATE module (gzipping) for a specific directory on my server. This is what I have in /etc/httpd/conf/httpd.conf
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
I can add something to my .htaccess file in the specific directory or even add a something to my /vhosts/domain.com/httpdocs/conf/vhosts.conf file. I can't seem to get it to work though. Any suggestions?

I removed my original code from /etc/httpd/conf/httpd.conf and added this to my vhost.conf on this domain
<Directory "/var/www/rockchurch.com/httpdocs">
AddOutputFilterByType DEFLATE html txt xml css js php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
php_admin_value open_basedir none
php_admin_value safe_mode off
Options FollowSymLinks
</Directory>
<Directory "/var/www/rockchurch.com/httpdocs/tiny">
RemoveOutputFilter DEFLATE html txt xml css js php
</Directory>
And works well. Apparently having it in /etc/httpd/conf/httpd.conf universally adds it to all domains, which is great, but can't be changed in specific directories elsewhere.

Another way to accomplish this is to put the following line in a .htaccess file in the target directory:
SetEnv no-gzip 1
It worked for me when the GZIP was causing issues with mod_substitute.

Related

angular 2 html video non english subtitles served by apache2

I have angular 2 app with latest angular-cli. App has html video player and is able to play videos with english subtitles (vtt). Video and subtitle files are served with apache2 and so is angular bundle from dist/. English subtitles are working fine but non english simply not appear in the video.
The key difference is when I access non-en sub. with chrome a get the encoding right (expected chars.). But when accessed (loaded by track tag) encoding is wrong (some messy chars.).
I only noticed difference in req header: accept, but I doubt that's the cause.
direct access with chrome:
loaded by track:
I'm including my apache configs (last lines are just tries with encoding, long time no see apache...).
apache2.conf:
...
<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
AddType text/plain .webapp
AddType text/xml .xml
AddType application/xml .xml
AddType application/javascript .js
AddType application/javascript .json
</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
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
AddDefaultCharset utf-8
<FilesMatch \.vtt$>
ForceType text/vtt;charset=utf-8
</FilesMatch>
AddType text/vtt .vtt
AddCharset UTF-8 .vtt
apache2 conf sites-enabled/000-default.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options -Indexes FollowSymLinks
AllowOverride None
Header set Access-Control-Allow-Origin "*"
</Directory>
<Directory /var/www/>
Header set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /var/www/hvp/>
Header set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / https://myserver/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/myserver/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/myserver/privkey.pem
<Directory /var/www/hvp/>
Header set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/https_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/https_access.log combined
</VirtualHost>
What could cause this behaviour? thx.
I managed to solve it.
First, when a file has a .vtt suffix chrome interprets it and finds right encoding. So comparing these two was pointless. Now when subs are working and I look in network tab I see messy chars anyway, but in player it's working.
Second, replacing commas with dots in time definition helped alongside with editing in webstorm and checking result in vlc.
So the real problem were the subtitle file's encoding and/or commas instead of dots in time def.

javascript gzip compression

I am using the following code in my .htaccess file kept in the server root to enable gzip compression. However, the javascript is not getting compressed.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/javascript application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
How to enable compression of javascript? I have checked that mod_deflate is enabled and the index page is getting compressed.
My website is hosted here.
We are not treating javascript as a simple text file here. text/javascript should be replaced by application/javascript as shown.
Application/x-javascript was used for IE as it ignored scripts.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/javascript application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
Cheers!

Content-Encoding: gzip doesn't work for text/html Content-Type

I use the config below in my .htaccess. However, whilst other Content-Type get gzipped, the text/html Content-Type doesn't. Anyone knows why?
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</IfModule>
Try to insert the AddType for html before it, like:
AddType text/html .html .htm
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
Here you have a complete list of MIME types: http://www.htaccess-guide.com/adding-mime-types/
*Edit: Try to change the rule then:
<ifModule mod_deflate.c>
<filesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
I ran across this while having the same issue on a Magento site. In my case the answer was to enable zlib output compression in php.ini because the html was being dynamically generated.
For me it was because of the charset. Whereas:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json text/json
did not work,
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json text/json application/javascript;charset=utf-8 text/css;charset=utf-8
worked. I didn't feel like looking for better answers like how I can instruct Apache to parse out the charset from the content type and I figured that just giving the whole String as is should work. Fortunately it did for me.

Gzip compression (mod_deflate) not working

I have just added, or tried to add, gzip compression to my website in order to make it faster. This is the code I have put into .htaccess I got from this answer.
<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
#The following line also enables compression by file content type, for the following list of Content-Type:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
So now I'm using a firebug extension called PageSpeed to monitor gzip compression and it is not working. I also use http://gtmetrix.com/ and the results are the same. Can anyone explain to me what more I have to do to enable gzip compression? Big thanks!

YSlow tells me site is not compressed even though it is

"Grade F on Compress components with gzip
There are 19 plain text components that should be sent compressed"
I have checked the compression of the main page, as well as all 19 components individually using "http://www.whatsmyip.org/http_compression/" and it shows compression in all of them. Furthermore, I ensured I'm not using a proxy and that "Accepting-Encoding" is gzip/deflate using "http://www.lagado.com/proxy-test". Contrary to these results, the mod_deflate log files is as follows (excerpt):
... "GET / HTTP/1.1" 4498/13306 (33%)
"GET /Home_Page/style.css HTTP/1.1"
-/- (-%) "GET /css/style.css HTTP/1.1" -/- (-%) "GET /css/slimbox.css HTTP/1.1" -/- (-%) "GET
/js/validator_o.js HTTP/1.1" -/- (-%)
...
So it's not compressing the css or js files? My config file is as follows:
<IfModule mod_deflate.c> SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/xml image/svg+xml application/javascript application/x-javascript application/atom_xml application/rss+xml application/xml application/xhtml+xml application/x-httpd-php application/x-httpd-fastphp
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 SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog /etc/httpd/logs/deflate_log deflate </IfModule>
Firefox 3.6.8
Windows 7 Professional
ISP: Rogers
Nevermind, it worked now. I set the modified the config file as follows
# Method 2: Compress all content, manually excluding specified file types
<IfModule mod_deflate.c>
# place filter 'DEFLATE' on all outgoing content
SetOutputFilter DEFLATE
# exclude uncompressible content via file type
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip)$ no-gzip
<IfModule mod_headers.c>
# properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>
Then did a browser cache reload and checked the log files and it was compressed. Yslow agreed.