My Blog
Scroll down to discover

How can I improve the TTFB?

May 5, 2018Category : Code/Web

Set up fastcgi_cache

In /etc/nginx/nginx.conf:

fastcgi_cache_path /etc/nginx-cache levels=1:2 keys_zone=phpcache:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

In your server’s .conf file likely in /etc/nginx/conf.d/modify the php handling block

 set $no_cache 0;
 location ~ [^/]\.php(/|$) {
 fastcgi_cache phpcache; # The name of the cache key-zone to use
 fastcgi_cache_valid 200 30m; # What to cache: 'Code 200' responses, for half an hour
 fastcgi_cache_methods GET HEAD; # What to cache: only GET and HEAD requests (not POST)
 add_header X-Fastcgi-Cache $upstream_cache_status; # Add header so we can see if the cache hits or misses
 fastcgi_cache_bypass $no_cache; # Dont pull from the cache if true
 fastcgi_no_cache $no_cache; # Dont save to the cache if true
 # the rest of your existing stuff to handle PHP files here


. . .
# `gzip` Settings
gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 2;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 1100;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
. . .
© Oliver / All rights reserved.
To top