Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 什么';Wordpress(nginx、varnish、apc)的服务器配置有什么问题?_Php_Wordpress_Nginx_Fastcgi_Varnish - Fatal编程技术网

Php 什么';Wordpress(nginx、varnish、apc)的服务器配置有什么问题?

Php 什么';Wordpress(nginx、varnish、apc)的服务器配置有什么问题?,php,wordpress,nginx,fastcgi,varnish,Php,Wordpress,Nginx,Fastcgi,Varnish,我正在为一个高流量的网站设置Wordpress后端(每月获得1500-2000万页面浏览量)。它的广告运行,但它的表现不如我所希望的 这些组成部分包括: Php5 fpm 快速CGI Nginx 清漆 APC W3TC Cloudflare(业务计划) 在Digitalocean上托管(32 GB内存、12核处理器、320 GB SSD磁盘) 我不是专家,但我通过在线博客和文档建立了一切。但我确信有些地方不对劲,因为有时我会遇到错误,比如“连接到数据库时出错”,第一次打开网站时速度慢(使用pin

我正在为一个高流量的网站设置Wordpress后端(每月获得1500-2000万页面浏览量)。它的广告运行,但它的表现不如我所希望的

这些组成部分包括:

  • Php5 fpm
  • 快速CGI
  • Nginx
  • 清漆
  • APC
  • W3TC
  • Cloudflare(业务计划)
  • 在Digitalocean上托管(32 GB内存、12核处理器、320 GB SSD磁盘)
  • 我不是专家,但我通过在线博客和文档建立了一切。但我确信有些地方不对劲,因为有时我会遇到错误,比如“连接到数据库时出错”第一次打开网站时速度慢(使用pingdom工具检查时等待时间长)

    因此,共享配置,以便这里的专家可以对服务器设置进行评论。我遗漏了什么吗

    请注意:下面的文件中还有其他参数,我已经记下了最相关的参数

    PHP设置:

    Page Cache (APC)
    Database Cache (APC)
    Object Cache (APC)
    Browser cache
    
    Minify: Off
    Rocket Loader: Off
    Caching level: Standard
    
    /etc/php5/fpm/php.ini

    max_execution_time = 180
    max_input_time = 60
    max_input_vars = 5000
    memory_limit = 256M
    post_max_size = 10M
    file_uploads = On
    upload_max_filesize = 10M
    max_file_uploads = 20
    default_socket_timeout = 90
    mysql.connect_timeout = 3000
    session.cache_expire = 180
    [apc]
    apc.write_lock = 1
    apc.slam_defense = 0
    apc.shm_size = "1024M"
    
    /etc/php5/fpm/pool.d/www.conf

    user = nginx
    group = nginx
    listen = /dev/shm/php-fpm-www.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    pm.max_children = 200
    pm.start_servers = 25
    pm.min_spare_servers = 25
    pm.max_spare_servers = 50
    pm.process_idle_timeout = 60s;
    pm.max_requests = 2000
    request_terminate_timeout = 600
    php_flag[display_errors] = off
    php_admin_value[error_reporting] = 0
    php_admin_value[error_log] = /var/log/php5-fpm.log
    php_admin_flag[log_errors] = on
    php_admin_value[memory_limit] = 1G
    
    Nginx:

    Page Cache (APC)
    Database Cache (APC)
    Object Cache (APC)
    Browser cache
    
    Minify: Off
    Rocket Loader: Off
    Caching level: Standard
    
    /etc/nginx/nginx.conf

    user  nginx;
    worker_processes  24;
    worker_rlimit_nofile 200000;
    events {
        worker_connections  4000;
        use epoll;
        multi_accept on;
    }
    http {
        server_names_hash_bucket_size  64;
        sendfile        on;
        tcp_nopush     on;
        tcp_nodelay on;
    
        keepalive_timeout  65;
        client_header_timeout 240;
        client_body_timeout 240;
        fastcgi_read_timeout 180;
        client_max_body_size 32m;
        gzip  on;
        gzip_disable "msie6";
    
            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/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
        include /etc/nginx/conf.d/*.conf;
        port_in_redirect off;
    }
    
    /etc/nginx/conf.d/default.conf

    server {
    client_max_body_size 10M;
    listen 8080;
    set $cache_uri $request_uri;
    
            # POST requests and urls with a query string should always go to PHP
            if ($request_method = POST) {
                    set $cache_uri 'null cache';
            }
            if ($query_string != "") {
                    set $cache_uri 'null cache';
            }
    
            # Don't cache uris containing the following segments
            if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
                    set $cache_uri 'null cache';
            }
    
            # Don't use the cache for logged in users or recent commenters
            if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
                    set $cache_uri 'null cache';
            }
    
            # Use cached or actual file if they exists, otherwise pass request to WordPress
            location / {
                   try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    location ~ \.php$ {
                fastcgi_buffers 256 16k;
                fastcgi_buffer_size 128k;
                fastcgi_max_temp_file_size 0;
                fastcgi_intercept_errors on;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
    
            }
    
            # BEGIN W3TC Browser Cache
            location ~ \.(css|htc|less|js|js2|js3|js4)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
        add_header X-Powered-By "W3 Total Cache/0.9.4.1";
    }
    location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
        expires 3600s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=3600, public";
        add_header X-Powered-By "W3 Total Cache/0.9.4.1";
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
        add_header X-Powered-By "W3 Total Cache/0.9.4.1";
    }
    # END W3TC Browser Cache
    }
    
    清漆:

    Page Cache (APC)
    Database Cache (APC)
    Object Cache (APC)
    Browser cache
    
    Minify: Off
    Rocket Loader: Off
    Caching level: Standard
    
    我从Dreamhost的VCL集合中获取了VCL文件:

    /etc/varnish/default.vcl

    backend default {
            .host = "127.0.0.1";
            .port = "8080";
    }
    
    import std;
    
    include "lib/xforward.vcl";
    include "lib/cloudflare.vcl";
    include "lib/purge.vcl";
    include "lib/bigfiles.vcl";        # Varnish 3.0.3+
    #include "lib/bigfiles_pipe.vcl";  # Varnish 3.0.2
    include "lib/static.vcl";
    
    acl cloudflare {
            # set this ip to your Railgun IP (if applicable)
            # "1.2.3.4";
    }
    
    acl purge {
            "localhost";
            "127.0.0.1";
    }
    
    # Pick just one of the following:
    # (or don't use either of these if your application is "adaptive")
    # include "lib/mobile_cache.vcl";
    # include "lib/mobile_pass.vcl";
    ### WordPress-specific config ###
    # This config was initially derived from the work of Donncha Ó Caoimh:
    # http://ocaoimh.ie/2011/08/09/speed-up-wordpress-with-apache-and-varnish/
    sub vcl_recv {
            # pipe on weird http methods
            if (req.request !~ "^GET|HEAD|PUT|POST|TRACE|OPTIONS|DELETE$") {
                    return(pipe);
            }
    
            ### Check for reasons to bypass the cache!
            # never cache anything except GET/HEAD
            if (req.request != "GET" && req.request != "HEAD") {
                    return(pass);
            }
            # don't cache logged-in users or authors
            if (req.http.Cookie ~ "wp-postpass_|wordpress_logged_in_|comment_author|PHPSESSID") {
                    return(pass);
            }
            # don't cache ajax requests
            if (req.http.X-Requested-With == "XMLHttpRequest") {
                    return(pass);
            }
            # don't cache these special pages
            if (req.url ~ "nocache|wp-admin|wp-(comments-post|login|activate|mail)\.php|bb-admin|server-status|control\.php|bb-login\.php|bb-reset-password\.php|register\.php") {
                    return(pass);
            }
    
            ### looks like we might actually cache it!
            # fix up the request
            set req.grace = 2m;
            set req.url = regsub(req.url, "\?replytocom=.*$", "");
    
            # Remove has_js, Google Analytics __*, and wooTracker cookies.
            set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js|wooTracker)=[^;]*", "");
            set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
            if (req.http.Cookie ~ "^\s*$") {
                    unset req.http.Cookie;
            }
    
            return(lookup);
    }
    
    sub vcl_hash {
            # Add the browser cookie only if a WordPress cookie found.
            if (req.http.Cookie ~ "wp-postpass_|wordpress_logged_in_|comment_author|PHPSESSID") {
                    hash_data(req.http.Cookie);
            }
    }
    sub vcl_fetch {
            # make sure grace is at least 2 minutes
            if (beresp.grace < 2m) {
                    set beresp.grace = 2m;
            }
    
            # catch obvious reasons we can't cache
            if (beresp.http.Set-Cookie) {
                    set beresp.ttl = 0s;
            }
    
            # Varnish determined the object was not cacheable
            if (beresp.ttl <= 0s) {
                    set beresp.http.X-Cacheable = "NO:Not Cacheable";
                    return(hit_for_pass);
    
            # You don't wish to cache content for logged in users
            } else if (req.http.Cookie ~ "wp-postpass_|wordpress_logged_in_|comment_author|PHPSESSID") {
                    set beresp.http.X-Cacheable = "NO:Got Session";
                    return(hit_for_pass);
    
            # You are respecting the Cache-Control=private header from the backend
            } else if (beresp.http.Cache-Control ~ "private") {
                    set beresp.http.X-Cacheable = "NO:Cache-Control=private";
                    return(hit_for_pass);
    
            # You are extending the lifetime of the object artificially
            } else if (beresp.ttl < 300s) {
                    set beresp.ttl   = 300s;
                    set beresp.grace = 300s;
                    set beresp.http.X-Cacheable = "YES:Forced";
    
            # Varnish determined the object was cacheable
            } else {
                    set beresp.http.X-Cacheable = "YES";
            }
      # Avoid caching error responses
            if (beresp.status == 404 || beresp.status >= 500) {
                    set beresp.ttl   = 0s;
                    set beresp.grace = 15s;
            }
    
            # Deliver the content
            return(deliver);
    }
    
    在W3TC上,我打开了以下功能:

    Page Cache (APC)
    Database Cache (APC)
    Object Cache (APC)
    Browser cache
    
    Minify: Off
    Rocket Loader: Off
    Caching level: Standard
    
    Cloudflare设置:

    Page Cache (APC)
    Database Cache (APC)
    Object Cache (APC)
    Browser cache
    
    Minify: Off
    Rocket Loader: Off
    Caching level: Standard
    

    请引导我。请建议更好的设置,如果有的话。

    你能运行一个像
    debug bar
    这样的插件来检查每页加载运行了多少db查询,特别是在生成缓存或未缓存的端点并报告时。让我检查一下,然后再给你回复。在主页上,它说:总查询:132总查询时间:244.5毫秒主页缓存?如果不是这样,那么每个请求获得132个查询的流量可能是您的db服务不断消亡的原因,页面加载时间缓慢可能是由于锁定了db行(取决于查询的内容)。是的,主页是使用APC缓存的。此外,APC上还启用了数据库缓存。