我在北卡罗来纳州夏洛特运行 VPS(Ubuntu 上的 nginx 版本 1.18.0)(QEMU 虚拟 CPU 版本 2.5+ 2399.998 MHz,turbo 高达 3.2 Ghz;2gb RAM)和我的 Wordpress 网站的 TTFB 不是很好。在美国大约为 200-300 毫秒,在加拿大和欧洲稍差,远离亚洲/澳大利亚。
我与 VPS 支持人员进行了交谈,他们将站点移至 FastCGI (Nginx + PHP-FPM) 并在 nginx.conf 中添加了一些代码,但它略微改进了 TTFB。我还通过 ISP Manager 启用了 HTTP/2。
无论如何,这是完整的配置:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
# gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
#Optimization
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_max_temp_file_size 0;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
fastcgi_connect_timeout 500;
fastcgi_send_timeout 500;
fastcgi_read_timeout 500;
client_header_timeout 1m;
client_header_buffer_size 2k;
client_body_buffer_size 256k;
ssl_buffer_size 4k;
large_client_header_buffers 4 8k;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
include /etc/nginx/vhosts/*/*.conf;
client_max_body_size 1024m;
server {
server_name localhost;
disable_symlinks if_not_owner;
listen 80;
listen [::]:80;
include /etc/nginx/vhosts-includes/*.conf;
location @fallback {
error_log /dev/null crit;
proxy_pass http://127.0.0.1:8080;
proxy_redirect http://127.0.0.1:8080 /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
access_log off ;
}
}
}
#Optimisation是由 VPS 支持添加的。
我玩了一些数字,但无济于事。你有什么建议?
这里有详细的TTFB(使用的tools.keycdn.com): 点击