May 5, 2018
66 Views
Comments Off on How can I improve the TTFB?

How can I improve the TTFB?

Written by

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

#fastcgi_cache
 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
 }

________________________________________________________________________________

/etc/nginx/nginx.conf
. . .
##
# `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;
. . .
Article Categories:
Code/Web
    http://linholiver.com

    https://linholiver.com/diary/about/