首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提高Wordpress - NGINX,PHP7.4,Redis,MariaDB专用服务器的性能

提高Wordpress - NGINX,PHP7.4,Redis,MariaDB专用服务器的性能
EN

Stack Overflow用户
提问于 2021-05-04 21:17:26
回答 1查看 463关注 0票数 0

我有一台专用的服务器,它的硬件配置如下:

代码语言:javascript
复制
CPU: Intel(R) Xeon(R) Gold 6226R CPU @ 2.90GHz 
RAM: 64GB
Disk: SSD 512GB

我的堆栈是:

代码语言:javascript
复制
SO: Ubuntu latest LTS
Web Server: Nginx 1.18.0
Language: PHP 7.4
Database: MariaDB 10.3.25

目前,TTFB是大约400毫秒,我有一些问题,缓慢的要求在Wordpress仪表板和网站的性能。

我知道站点端的优化,但是,我测试了一些东西以获得真正的问题:服务器端。

我有超过200个网站,所有在Wordpress和"Tiedye",使用的只是最好的插件。所有这些都是连接到Cloudflare与最好的选择和缓存插件(WP火箭)。

关于软件的倾诉,请遵循:

NGINX

代码语言:javascript
复制
user www-data;

worker_processes auto;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log crit;

pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*;

events {
        worker_connections 4096;
        multi_accept on;
        use epoll;
}

http {
        #BASIC CACHE
        open_file_cache max=200000 inactive=20s;
        open_file_cache_valid 30s;
        open_file_cache_min_uses 2;
        open_file_cache_errors on;

        access_log off;
        server_tokens off;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 30;
        send_timeout 2;
        keepalive_requests 100000;
        reset_timedout_connection on;
        types_hash_max_size 2048;
        #LARGE URL, LARGE REQUESTS AND SIZES IMPROVE
        large_client_header_buffers 4 256k;
        client_max_body_size 500M;
        client_header_buffer_size 3M;
        client_body_buffer_size 128k;
        client_body_timeout   30m;
        client_header_timeout 30m;
        proxy_send_timeout 6000;
        proxy_read_timeout 6000;
        fastcgi_read_timeout 3600;
        fastcgi_send_timeout 3600;
        server_names_hash_bucket_size 512;

        #SSL
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
        ssl_ecdh_curve secp384r1;
        ssl_session_tickets off;
        ssl_buffer_size 4k;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 1h;

        #DEFAULT
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        #SECURITY
        limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;        limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;

        #COMPRESS AND CACHE
        gzip on;
        gzip_disable "msie6";
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        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 image/jpeg image/png image/jpg;

        fastcgi_buffers 8 16k;
        fastcgi_buffer_size 32k;
        fastcgi_cache_use_stale error timeout invalid_header http_500;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_cache_path /var/cache/nginx/fastcgi levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
        fastcgi_cache_key "$scheme$request_method$host$request_uri";

        proxy_cache_path /var/cache/nginx/proxy levels=1:2 keys_zone=PROXY:10m max_size=10g inactive=60m use_temp_path=off;
        proxy_cache_revalidate on;
        proxy_buffering off;
        proxy_request_buffering off;
}

NGINX/PHP

代码语言:javascript
复制
### SERVER ###

index index.php index.html index.htm index.nginx-debian.html;

#RULES FOR NOT CACHE

set $skip_cache 0;

if ($request_method = POST) {
    set $skip_cache 1;
}

if ($query_string != "") {
    set $skip_cache 1;
}

if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
    set $skip_cache 1;
}

if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
}

#RULES AND REWRITES

location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
  rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
  rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
  rewrite ^.*/sitemap_index\.xml$ /index.php?sitemap=1 last;
  rewrite ^.*/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
  rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;
  rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
  rewrite ^/geo_sitemap\.xml$ /index.php?sitemap=wpseo_local last;
  rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;

  access_log off;
}

location ~* /(?:uploads|files|wp-content|wp-includes|akismet)/.*.php$ {    deny all;
    access_log off;
    log_not_found off;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off;
        log_not_found off;
        expires max;
        add_header Cache-Control "max-age=2592000";
}

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
        add_header Cache-Control "max-age=0";
}

location ~* \.(?:rss|atom)$ {
        add_header Cache-Control "max-age=3600";
}

location ~* \.svgz$ {
        access_log off;
        gzip off;
        expires 360d;
        add_header Cache-Control "max-age=2592000";
}

location ~* \.(?:css|js)$ {
        access_log off;
        log_not_found off;
        expires 360d;
        add_header Cache-Control "max-age=31536000";
}

location = /robots.txt {
        access_log off;
        log_not_found off;
}

location ~ /\.ht {
        deny all;
        access_log off;
        log_not_found off;
}

location ~ /\.user.ini {
        deny all;
        access_log off;
        log_not_found off;
}

location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $fastcgi_script_name = 404;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_index index.php;
        fastcgi_cache WORDPRESS;
        fastcgi_cache_valid 200 30m;
        fastcgi_cache_methods GET HEAD;
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;

        proxy_cache PROXY;

        # Hide PHP Version

        fastcgi_hide_header X-Powered-By;
        proxy_hide_header X-Powered-By;

        add_header X-Fastcgi-Cache $upstream_cache_status;
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";

        include fastcgi.conf;

        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}

location / {
        try_files $uri $uri/ /index.php?$args;
}

PHP自定义CONFIGS:

代码语言:javascript
复制
memory_limit = 512M
max_input_time = 50000
max_execution_time = 50000
expose_php = Off
post_max_size = 20M

--- POOL ---

pm = static
pm.max_children = 220
pm.max_requests = 0
request_terminate_timeout = 20000

MARIADB自定义CONFIGS:

代码语言:javascript
复制
innodb_buffer_pool_size = 18G
innodb_buffer_pool_instances = 18
innodb_log_file_size = 6G
innodb_log_buffer_size = 512M
innodb_write_io_threads = 8
innodb_read_io_threads = 8
max_allowed_packet = 512M
max_connections = 500
table_open_cache = 6000
table_open_cache_instances = 8
table_definition_cache = 2000
tmp_table_size = 64M
max_heap_table_size = 64M
thread_cache_size = 100
key_buffer_size = 128M
query_cache_type = 0
query_cache_size = 0
log_warnings = 2

关于这许多信息和信任,一些直接提示,以提高TTFB和我的网站的速度?

如果你是这方面的专家,并想帮我,我会考虑“付一杯咖啡”比较后的结果。

EN

回答 1

Stack Overflow用户

发布于 2021-05-05 01:43:48

WP在wp_postmeta上有一些草率的索引。这可能解释缓慢的查询,这可能解释高的TTFB。下面是模式修复的详细信息:

http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta

系统交换了吗?数据集是否小于18 Is?这两个问题都可能导致其他(不太可能的)补救办法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67392351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档