问题原文
原帖链接 · Christian · CC BY-SA 4.0
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.
已采纳解答
原帖链接 · Christian · CC BY-SA 4.0
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 by fastcgi_ like so:
fastcgi_cache_path /var/www/ma_cache levels=1:2 keys_zone=ma_cache:10m use_temp_path=off max_size=20g;
fastcgi_cache ma_cache;
fastcgi_cache_valid 720h;
fastcgi_ignore_headers Set-Cookie;
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
