服务器响应时间

服务器响应时间

在这件事让我做出不可想象的事情之前,请有人来帮助我。我怎么能有 16GB RAM、6 核 digital ocean droplet。在 Wordpress 上运行,带有 34 个插件。链接到 Cloudflare 并建立所有缓存机制。但我的网站仍然需要 50 秒才能加载。我已经在 Google 上搜索了一次又一次,尝试了所有我能在网上找到的东西,但问题仍然存在。问题变得越来越严重,当我在任何时刻有大约 300 个实时用户时,我收到 502 错误。我已经优化、优化、优化、优化,但我对此感到非常厌倦。请有人来帮助我。我该怎么做才能让我的网站足够快,并避免在大量实时用户在线时出现 http 错误。我知道 6GB RAM digitalocean droplet 将承载超过 5000 个实时用户,并且仍然非常快。请问我做错了什么?我遗漏了什么?我需要所有我能得到的帮助。有人应该给我一个配置设置来承载这些流量,以及我需要不断做哪些事情来保持速度。请帮帮我。

我知道这会被标记为偏离主题。但这是我能跑到的最后一个地方。这基本上是我在 php-fpm 上的所有活动设置

[www]

user = www-data
group = www-data


listen = /run/php/php7.2-fpm.sock


listen.owner = www-data
listen.group = www-data

pm = dynamic


pm.max_children = 5

pm.start_servers = 2

pm.min_spare_servers = 1

pm.max_spare_servers = 3

这是我的 nginx conf 文件中的内容

        user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;

    events {
        worker_connections 2048;
        # 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;
        #more_set_headers "Server: wakanda";

        # 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 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GC$;

        ##
        # Logging Settings
        ##

        #access_log /var/log/nginx/access.log;
        access_log off;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_min_length  1000;
        # gzip_buffers 32 16k;
        # gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";


        #####
        #Security Headers
        ######

        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "no-referrer-when-downgrade" always;
        add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;


        # Optimize session cache
        ssl_session_cache shared:SSL:50m;
        ssl_session_timeout 1d;

        # Enable session tickets
        ssl_session_tickets on;

        # OCSP Stapling
        ssl_stapling on;
        ssl_stapling_verify on;
        resolver 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
        resolver_timeout 2s;


        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

    }

这是我在 mysql 上的内容

        [mysqld_safe]
    socket      = /var/run/mysqld/mysqld.sock
    nice        = 0

    [mysqld]
    #
    # * Basic Settings
    #
    user        = mysql
    pid-file    = /var/run/mysqld/mysqld.pid
    socket      = /var/run/mysqld/mysqld.sock
    port        = 3306
    basedir     = /usr
    datadir     = /var/lib/mysql
    tmpdir      = /tmp
    lc-messages-dir = /usr/share/mysql
    skip-external-locking
    #
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address        = 127.0.0.1
    #
    # * Fine Tuning
    #
    key_buffer_size     = 16M
    max_allowed_packet  = 16M
    thread_stack        = 192K
    thread_cache_size       = 32
    # This replaces the startup script and checks MyISAM tables if needed
    # the first time they are touched
    myisam-recover-options  = BACKUP

    max_heap_table_size    = 64M
    tmp_table_size         = 64M
    max_connections        = 1000
    max_user_connections   = 200
    table_open_cache       = 2000
    join_buffer_size       = 1M
    #thread_concurrency     = 10
    #
    # * Query Cache Configuration
    #
    query_cache_limit   = 2M
    query_cache_size        = 16M

    #
    # Error log - should be very few entries.
    #
    log_error = /var/log/mysql/error.log

    expire_logs_days    = 10
    max_binlog_size   = 100M

    #
    # * InnoDB
    #
    #default_table_type            = InnoDB
    # 80% of ram that is dedicated for the database (this needs to be adjusted to your system)
    innodb_buffer_pool_size        = 7G

    innodb_buffer_pool_instances   = 2 
    innodb_log_file_size           = 64M
    innodb_log_files_in_group      = 2

这是网站配置文件

        server {
            root /var/www/html/wakanda.ng/public;
            index index.php index.html index.htm index.nginx-debian.html;
            server_name wakanda.ng www.wakanda.ng;

        access_log /var/log/nginx/wakanda.ng/wakanda_access_log;
        error_log   /var/log/nginx/wakanda.ng/wakanda_error_log   error;

            location / {
                    #try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
            }

        error_page 401 /custom_401.html;
            location = /custom_401.html {
                    root /usr/share/nginx/html;
                    internal;
            }

        location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 365d;
        }

            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_read_timeout 300;
            }

        # Protect wp-admin
    location /wp-admin {
        auth_basic "Admin Login";
        auth_basic_user_file /var/www/html/wakanda.ng/.htpasswd;
    }

    # Protect wp-login.php script
    location /wp-login\.php$ {
        auth_basic "Admin Login";
        auth_basic_user_file /var/www/html/wakanda.ng/.htpasswd;
    }

    # Allow access to the admin-ajax.php, all the ajax calls
    # are routed this way in WordPress
    location /wp-admin/admin-ajax.php {
        allow all;
    }
            location ~ /\.ht {
                    deny all;
            }

        listen 443 http2 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/wakanda.ng/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/wakanda.ng/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


    }
    server {   
       if ($host = www.wakanda.ng) {
            return 301 https://$host$request_uri;
        } # managed by Certbot


        if ($host = wakanda.ng) {
            return 301 https://$host$request_uri;
        } # managed by Certbot


            listen 80;
            server_name wakanda.ng www.wakanda.ng;
        return 404; # managed by Certbot

    }

我不知道哪些是需要的,哪些是不需要的,所以我把它们都包括了。网站是 wakanda.ng。你可以亲自去看看。

相关内容