• 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 Nginx proxy_cache_path

toomanylogins

Basic Pleskian
I am trying to set up my Plesk Joomla website to reverse proxy some requests to a application server and would like to implement the cache.

Is it possible to setup up the proxy cache for nginx. The directive proxy_cache_path nneeds to be set at the http context within the configuration file however it seems that Plesk implementation only allows directives and the server context.

if I had this directive to be nginx settings I get Invalid nginx configuration: nginx: [emerg] "proxy_cache_path" directive is not allowed here

Thanks
Paul
 
Thanks Lloyd, That file does not exist in plesk 12.5 can anyone confirm its ok to create this.

I realise this is global but I am assuming that the cache is only activated for sites using proxy_cache mycache; in the plesk nginx settings so existing sites are unaffected.

I can setup multiple proxy_cache_path with different zones to assigns to different locations.

If I create file is it included via this line include /etc/nginx/conf.d/*.conf; ? I have a file zz010_psa_nginx.conf this is plesk do not modify.

Cheers
Paul
 
Hi Paul,
yes, it's ok to create the file if you don't have it, just make sure you restart nginx after adding the snippet.
Kind regards

Lloyd
 
Thanks LLoyd,

I have created the file with this line as folllows
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=qms:10m inactive=24h max_size=1g;

This is on ubuntu so I have guessed the path and added folder /var/cache/nginx but not sure if this supposed to be relative to the root folder or var/www/vhosts. Perms are 0755.

Then added this to a plesk domain nginx settings.

location /lightning-web/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache qms;
proxy_pass http://xxx.xx.xx.xxx/lightning-web/;
}

However nothing seems to be caching ie /var/cache/nginx is empty. I have reload nginx a few times..

Cheers
Paul
 
Hello Lloyd, thanks for the reply I've created file as follows.

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=qms:10m inactive=24h max_size=1g;

And then included the following directives in the Plesk nginx settings for a domain.

location /lightning-web/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache qms;
proxy_pass http://xxx.xx.xxx.xxx/lightning-web/;
}

I was unsure whether the path to the cache is relative to the root folder or not so I guessed and created folder root/var/cache/nginx with perms 0755 as this is ubuntu and it seems this location contains the cache for Apache and the other applications.

Reloaded nginx a couple of times but the folder remains empty ie it would appear nothing is being cached.

Also tried removing levels=1:2

Regards
Paul.
 
Hi,
the cache path is relative to /. When I tested yesterday I used /tmp/nginx_cache, but you'd probably want to use /var/cache/nginx_cache/.
I was able to get it running by simply adding...

Code:
proxy_cache            STATIC;
proxy_cache_valid      200  1d;

In your case STATIC would be CMS, in the domains Additional Nginx Directives (I got a location conflict when adding location /).
Anyway, that should get it going.
Kind regards

Lloyd
 
Thanks LLoyd. I don't think my eyes were deceiving me but when I renamed the folder /var/cache/nginx which had owner www-data to /var/cache/nginx_cache the owner became nginx!

Moving the

proxy_cache qms;
proxy_cache_valid 200 1d;

Out of the location did the trick it is now caching.
Thanks for the help.
Paul
 
Hi Paul,
I didn't actually create the folder, I just defined it and let Nginx do the rest.
Nginx created it as...

Code:
# ls -ld /var/cache/nginx_cache
drwx------ 8 nginx root 4096 Aug  5 11:36 /var/cache/nginx_cache

Anyway, glad it helped.
Kind regards

Lloyd
 
For further ref if you are proxying more than one site via nginx you need a different cache folder for each zone. otherwise if you have files with the same name ie theme.css then this file can be delivered to two different websites because the file exists in a single cache.
 
Back
Top