• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved Plesk Onyx - .htaccess Expires Headers not working

ChrisScottUK

New Pleskian
Hi there,

I use WP Fastest Cache Plugin, but the expires headers in .htaccess aren't being respected.
I'm using Plesk Onyx with Nginx reverse proxy to apache. I thought using it as a reverse proxy would repsect the .htaccess rules (I know that Nginx on it's own doens't use .htaccess)

Any ideas why this doesn't work?


Code:
# BEGIN LBCWpFastestCache
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/svg+xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
</IfModule>
<IfModule mod_headers.c>
Header set Expires "max-age=2592000, public"
Header unset ETag
Header set Connection keep-alive
FileETag None
</IfModule>
</FilesMatch>
# END LBCWpFastestCache
 
It does not work, because when you use Nginx as reverse proxy, it serves static files directly (bypassing Apache). As your Expire instructions are set to apply to exactly those static files, they are never executed.

Instead enter a section like this
Code:
location ~*  \.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)$ {
   expires 365d;
}
into the "Additional Nginx directives" in the Nginx web server settings field.
 
Hi Peter!

Thanks for providing this code. I'm facing the same problem as WebsiteWI mentioned above: The site loads significantly faster but the whole layout is broken.

Would it be possible to provide a screenshot of a recommended plesk setup for Wordpress, please? I attached our setup for your reference. With this setup the site layout is displayed correctly but I'm told by pingdomtools that I should add expires headers. Besides that the performance is good and the layout is correct.

If I add your code, the layout will be broken but the site will get lightning fast (as it does not load graphics anymore).

Also if I activate "Statische Dateien direkt durch nginx bedienen", the site layout will be broken in the same way as with your code.

Thanks,

Kaik
 

Attachments

  • General Appache settings.jpg
    General Appache settings.jpg
    135.2 KB · Views: 22
  • nginx-settings.jpg
    nginx-settings.jpg
    126.7 KB · Views: 23
In this case, some files like images or css (stylesheets) are generated on-the-fly or need rewrite rules in an .htaccess file to load from their physical disk locations. In such a configuration you can only either provide rewrite rules for these files that do the same as the .htaccess rewrite rules you are using but are specificially designed for Nginx, or you cannot use the "serve static files" by Nginx function. As an alternative you can try to omit the file extensions css, jpg, jpeg, png, gif and js from the location directive. However, these are exactly the file types that are most relevant to be served by Nginx, so is questionable whether it will still make sense to use the Nginx setup at all.
 
Hi Peter.
I have the same problem.
a php website that use a on the fly resize program for photos.
If i do what you say above, the chache works fine, but the photos of the resize program does work
So, i have all the photos but the types as
/red/w260-h200/anuncios/59/fotos/thumbnail-001.jpg

does appear on the website

That photos script is located on " red" folder

what can i do ?

Thank you
 
I am unsure whether I understand you correctly. Could you please re-word what exactly you are doing, what the outcome is and what the outcome should be instead?
 
Hi Peter. I will try
1º I have a website with php ( no CMS ). version 7.2 php and apache manage the cache throught .htacess
I am interestin in nginx to manage the cache for css and images, so i do what soy say here, go to pleask , click on nginx, a add :
location ~* \.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)$ {
expires 365d;
}

3º If noe i check on google speed, the problem about cache desappear ( no errror ) but my website has a resize image script on the fly --> SLIR (Smart Lencioni Image Resizer)

so, the problem is that all images that resize that script does not appear on the website . The others images may be seen on the page

A posibble solution should be to modify the code you gave here in order to bypass the execute or that script. It is posible ?. What do you sugests?

Thank you for your time
 
When you are using a script to generate images it is not possible to cache the images at the same time, because then the script will not be executed. I do not see how it would be possible to generate resized image versions for some images, e.g. only n out of m .jpg files, while others should be served statically. So I think that there is no solution to your question.
 
Back
Top