php - How to configure basic FastCGI caching on nginx (Ubuntu 16.04) -


i'm trying basic fastcgi caching work, running trouble after following this tutorial.

on fresh installation of ubuntu 16.04, ran following commands:

apt-get update apt-get install -y nginx apt-get install -y php-fpm 

i changed /etc/nginx/sites-available/default to:

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;     } } 

after adding file called time.php in server document root (/var/www/html) following contents:

<?php echo time();

and navigating ip/time.php, file executes , displays timestamp. on reloads, fresh timestamps displayed.

if uncomment above lines, blank screen <html><body></body></html> loads.

why adding:

        fastcgi_cache myapp;         fastcgi_cache_valid 200 60m; 

result in blank html page? how can fixed cache time.php , serve cached version future requests?

note: did see /etc/nginx/cache created , contain data. changed directory 777 permissions eliminate permission issues.

$ sudo mkdir -p /var/cache/nginxfastcgi $ chown www-data: /var/cache/nginxfastcgi 

then in config

    fastcgi_cache_path /var/cache/nginxfastcgi levels=1:2 keys_zone=fastcgicache:10m inactive=10m max_size=64m;     fastcgi_cache_key $scheme$request_method$host$request_uri;      fastcgi_cache_lock on;     fastcgi_cache_use_stale error timeout invalid_header updating http_500;     fastcgi_cache_valid 5m;     fastcgi_ignore_headers cache-control expires set-cookie;  server {     listen 80;      root **************;     index index.php index.html index.htm;      server_name *************;      location / {             try_files $uri $uri/ /index.php?$query_string;     }      location ~ \.php$ {             try_files $uri /index.php =404;             fastcgi_split_path_info ^(.+\.php)(/.+)$;             fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;             fastcgi_index index.php;             fastcgi_param script_filename $document_root$fastcgi_script_name;             include fastcgi_params;             add_header x-cache $upstream_cache_status;             fastcgi_cache fastcgicache;     } } 

Comments