should the dot character be escaped in this situation:
<FilesMatch "^/(app.csv|translation.csv*)$">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</FilesMatch>
Such as:
<FilesMatch "^/(app\.csv|translation\.csv*)$">
Or is Apache able to understand that this is a file extension?
Related
The system is up and running in elasticbeanstalk here is added configs in the .ebextensions folder (located in folder root)
nginx-proxy.config
option_settings:
aws:elasticbeanstalk:environment:proxy:
GzipCompression: 'true'
ProxyServer: nginx
gzip.config
files:
/etc/nginx/conf.d/gzip.conf:
content: |
gzip on;
gzip_types application/json application/xml text/html text/xml text/plain application/javascript text/css;
gzip_vary on;
Tried with tomcat-settings.config too, but the result is the same
option_settings:
aws:elasticbeanstalk:environment:proxy:
GzipCompression: 'true'
ProxyServer: nginx
only getting these response headers yet
cache-control →no-cache, no-store, max-age=0, must-revalidate
content-type →application/json
date →Mon, 31 Jan 2022 08:31:22 GMT
expires →0
pragma →no-cache
server →nginx/1.20.0
strict-transport-security →max-age=31536000 ; includeSubDomains
vary →Origin, Access-Control-Request-Method, Access-Control-Request-Headers
x-content-type-options →nosniff
x-frame-options →DENY
x-xss-protection →1; mode=block
Application properties file
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css
Tried by adding this header for postman too
'accept-encoding: gzip'
its works after apply this
#Bean
public Filter compressingFilter() {
CompressingFilter compressingFilter = new CompressingFilter();
return compressingFilter;
}
dependency used this one
<dependency>
<groupId>net.sourceforge.pjl-comp-filter</groupId>
<artifactId>pjl-comp-filter</artifactId>
<version>1.6.4</version>
</dependency>
work as a charm :-)
I have created Angular App for which I am facing performance issues as my main.js file size is 3.76 MB. So I looked for enabling gzip compression on server. It worked for Apache in windows but not for Solaris 11.
So is there a different way to enable compression on Solaris 11 for Apache-2.4.
On Windows I enabled compression for Apache Server by uncommenting following module line inside httpd.conf of Apache and file size reduced to 680KB
LoadModule deflate_module modules/mod_deflate.so
And adding following at the end of httpd.conf file
<IfModule mod_deflate.c>
<FilesMatch "\.(html|txt|css|js|php|pl)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
For Solaris I tried same but it's not working. JS files transferred size and resource size is still same.
Also tried to put .htaccess file in root of my app with following lines
<Directory /var/apache2/2.4/htdocs/>
<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
</IfModule>
</IfModule>
Header append Vary User-Agent env=!dont-vary
</Directory>
Anyone has any ideas about how to get it worked for Solaris 11 for Apache 2.4
Thanks in Advance.
Here is how I enabled cache for images, JavaScript and CSS in Apache httpd.conf
<IfModule mod_expires.c>
<FilesMatch "\.(jpe?g|png|gif|js|css)">
ExpiresActive On
ExpiresDefault "access plus 7 day"
FileETag None
</FilesMatch>
</IfModule>
My question is how to form FilesMatch regex negative-assertions to get result no-cache for everything except images, JavaScript and CSS. Below does not work.
# DISABLE ALL CACHING EXCEPT IMAGES,JAVASCRIPT AND CSS
<FilesMatch "\.?!(jpe?g|png|gif|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Note "CACHING IS DISABLED"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>
</FilesMatch>
Untested, but I think this should be (?<!\.(html|htm|js|css|json))$. See the question I linked as a duplicate for more details.
I am trying to tell browsers to cache any type of image files (png/jpg/gif/etc) from my application, by setting up an .htaccess file in the root of my Django application.
.htaccess
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/gif "access plus 365 days"
ExpiresByType image/jpeg "access plus 365 days"
ExpiresByType image/png "access plus 365 days"
</IfModule>
Apache
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
<Directory />s
AllowOverride All
</Directory>
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/timbaney1989/logs/user/access_baneydev.log combined
ErrorLog /home/timbaney1989/logs/user/error_baneydev.log
Before adding the AllowOverride All option, I was getting an internal server error, but now my app is running fine. When I check the network however and see images being loaded, I don't see the expire header anywhere on that image. Also the server says it is Nginx ? Is this a normal thing to be running your application on an Apache serve, and have an Nginx server loading your static files ? Is there somewhere in my Django application or Apache httpd.conf file that I am missing, or have entered incorrectly ?
It looks the twitter.png file gets a 404:
HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html
Date: Sun, 06 Nov 2016 06:44:39 GMT
Server: nginx
Vary: Accept-Encoding
Here's a modified version of the solution by Nicholas Kuechler
location ~* \.(png|jpe?g|gif|ico|tiff)$ {
expires max;
log_not_found off;
access_log off;
}
If it's getting 404, you likely have the root directive incorrectly setup for location-block inheritance. Confirm that the root (DocumentRoot) is correct, and that the file exists relative to the root path, and it should show.
You could also follow this guide for uWSGI and NGINX to replace apache, and set up static files as an alias in a location block instead, and add the headers from my previous answer.
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
I have cache control set by htaccess for all images by this
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
</IfModule>
It works great, but I have also pictures from web camera, which change every 20 minutes. So I need to cache all images except these from camera.
I can write regular expression for those from web camera, they have name which others pictures never can have. But how to put there some condition?
You can disable cache for certain matching files :
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
</IfModule>
# disable caching for IMG_20130420_535615.jpg type of files
<FilesMatch "IMG_[0-9]+_[0-9]+\.jpg$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Tue, 14 Jan 1975 01:00:00 GMT"
</ifModule>
</FilesMatch>