Page 1 of 1

Как уменьшить TTFB на Nginx + Fastcgi

Posted: Wed Mar 08, 2017 1:47 pm
by sytrus
Здравствуйте, пользуюсь vestacp недавно, поэтому возникли трудности с настройкой. Связка Nginx+phpfpm на кеше fastcgi дает громадный ttfb (0.9с). В настройках nginx включен кеш, но к сожалению это не поменяло ситуацию. Сайт на cms wordpress.

Если надо линк на сайт, скину в лс. Конфиги nginx (domain заменил в целях конспирации :-) ):
SpoilerShow
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 62.109.17.167:80;
server_name domain.ru http://www.domain.ru;
root /home/domain/web/domain.ru/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/domain.ru.log combined;
access_log /var/log/nginx/domains/domain.ru.bytes bytes;
error_log /var/log/nginx/domains/domain.ru.error.log error;

location / {
try_files $uri $uri/ /index.php;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}

location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}

fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m;

}

location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css)$ {
expires max;
add_header Cache-Control public;
}

#Cache everything by default
set $no_cache 0;

#Don't cache POST requests
if ($request_method = POST)
{
set $no_cache 1;
}
#Don't cache the following URLs
if ($request_uri ~* "/(administrator/|login.php)")
{
set $no_cache 1;
}

#Don't cache if there is a cookie called PHPSESSID
if ($http_cookie = "PHPSESSID")
{
set $no_cache 1;
}




}

#WPProtect:
location ~* /wp-includes/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
location ~* /wp-content/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
location ~* /themes/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
location ~* /plugins/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
location = /xmlrpc.php {
deny all;
access_log off;
log_not_found off;
}
location @wordpress {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}





error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;

location /error/ {
alias /home/domain/web/domain.ru/document_errors/;
}

location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}

location /vstats/ {
alias /home/domain/web/domain.ru/stats/;
include /home/domain/web/domain.ru/stats/auth.conf*;
}

include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;

pagespeed On;
pagespeed RewriteLevel CoreFilters;
pagespeed SupportNoScriptEnabled false;
pagespeed Disallow "*/wp-admin/*";
pagespeed Disallow */amp/*;

# HTTPS Support
pagespeed FetchHttps enable,allow_self_signed;

pagespeed EnableFilters lazyload_images,collapse_whitespace,insert_dns_prefetch,dedup_inlined_images,defer_javascript,pedantic,trim_urls,sprite_images,extend_cache_pdfs,remove_comments,resize_mobi$

pagespeed EnableFilters convert_jpeg_to_progressive;

pagespeed FileCachePath /var/ngx_pagespeed_cache;

location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

include /home/domain/conf/web/nginx.domain.ru.conf*;
}

Re: Как уменьшить TTFB на Nginx + Fastcgi

Posted: Thu Mar 09, 2017 12:37 pm
by skurudo
Думаю, что нужно читать и оптимизировать:
* https://www.digitalocean.com/community/ ... swer=29063
* http://serverfault.com/questions/350062 ... first-byte

Очень похоже на религиозный вопрос с этим первым байтом, как по мне :)