【发布时间】:2016-12-06 15:29:37
【问题描述】:
我正在尝试使用基本的 FastCGI 缓存,但在关注 this tutorial 后遇到了麻烦。
在全新安装 Ubuntu 16.04 时,我运行了以下命令:
apt-get update
apt-get install -y nginx
apt-get install -y php-fpm
然后我将/etc/nginx/sites-available/default 更改为:
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include snippets/fastcgi-php.conf;
# fastcgi_cache MYAPP;
# fastcgi_cache_valid 200 60m;
}
}
在服务器文档根目录 (/var/www/html) 中添加一个名为 time.php 的文件后,其内容如下:
<?php echo time();
并导航IP/time.php,文件执行并显示时间戳。重新加载时,会显示新的时间戳。
如果我取消注释以上行,则只会加载带有 <html><body></body></html> 的空白屏幕。
为什么要加:
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m;
导致空白的html页面?如何解决此问题以缓存 time.php 并将缓存的版本提供给未来的请求?
注意:我确实看到 /etc/nginx/cache 已创建并包含数据。我将目录更改为777权限以消除权限问题。
【问题讨论】:
-
你试过重启nginx吗? /etc/init.d/nginx 重启
-
是的,我尝试了许多不同的配置(每次都重新启动),但没有任何效果。
标签: php ubuntu caching nginx fastcgi