I'm setting up Nginx as a web server processing PHP via php-fpm on Ubuntu 18.04. This is working great and is lightning fast. I'm attempting to configure it to cache pages to see if performance gets even better. However, I've been unable to get it to cache pages to disk. The directory I've specified to save the pages to is currently set open to the world (777).
Here are relevant portions of my configuration files and a sample page request header:
nginx.conf:
http {
proxy_cache_path /var/www/ma_cache levels=1:2 keys_zone=ma_cache:10m use_temp_path=off max_size=20g;
}
sites-available/mysite.conf:
server {
proxy_buffering on;
proxy_cache ma_cache;
proxy_cache_valid 720h;
proxy_ignore_headers Set-Cookie;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
Sample Response:
content-encoding: gzip
content-type: text/html; charset=UTF-8
date: Thu, 14 Nov 2019 21:08:13 GMT
server: nginx/1.14.0 (Ubuntu)
status: 200
There must be something that I'm misunderstanding or simply being stupid about. I'm hopeful someone can point me in the right direction.
Since we're not using Nginx as a proxy, but as a webserver itself, the configuration options change compared to the documentation. The caching options prefaced with
proxy_
are instead prefaced byfastcgi_
like so: