大网数据广告活动
服务器运维问答

Nginx not caching pages to disk

· 52CE 我爱测

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 bee…

问题原文

原帖链接 · 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;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-11-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。