Nginx 子域名 Wordpress 重写规则 - APC FPC - 慢得像乌龟。为什么?

Nginx 子域名 Wordpress 重写规则 - APC FPC - 慢得像乌龟。为什么?

在 Ubunty 10.04 Nginx(最新版本之一)上使用插件在 Wordpress 子域多站点上运行。

APC 我有最新版本的 php,我运行 4 个几乎没有流量的网站(每个网站每天 30 次点击),带有 rackspace 的云服务器(2gig 内存,基本型号)似乎 50% 的内存使用率是正常的。它可以工作,但是

1) 我正在使用 batcache、apc 插件,但我不知道应该给它们多少内存,目前是 128MB。由于日志中出现错误要求增加内存,我将 APC 设置为 128MB,如下所示。https://i.stack.imgur.com/hnwJd.jpg<--- apc.php 页面图像

2)javascript 没有被 gzip 压缩。

3)index.php 位于每个 url 内,如果删除它,wordpress 会抛出错误。

下面是我的 cfg 文件,请帮我看看缺少了什么,我查看了 50 个 nginx 配置页面,并从中改编了这个,因为它们都不适合我的设置

nginx.cfg

user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
      use epoll; #v1
     # multi_accept on; #v1
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
      #tcp_nodelay off; #v1
    tcp_nodelay on; #v2
    server_tokens off;

    include mime.types;

    default_type  application/octet-stream;
    index index.php index.htm index.html redirect.php;

    keepalive_timeout 15;
    keepalive_requests 2000;
    types_hash_max_size 2048;

    ##necessary if using a multi-site plugin
    server_name_in_redirect off;
    ##necessary if running Nginx behind a reverse-proxy
    port_in_redirect off;
    server_names_hash_bucket_size 64;

    open_file_cache max=1000 inactive=300s;
    open_file_cache_valid 360s;
    open_file_cache_min_uses 2;
    open_file_cache_errors off;

    client_body_buffer_size 128K;
    client_header_buffer_size 1k;
    client_max_body_size 2m;
    large_client_header_buffers 4 8k;

    client_body_timeout   10m;
    client_header_timeout 10m;
    send_timeout          10m;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;

    gzip_vary on;
    gzip_proxied any; #v2
      #gzip_proxied     expired no-cache no-store private auth; #v1
    gzip_comp_level 6;
    gzip_min_length  1000;
    gzip_buffers 32 8k; #v1
   # gzip_buffers 16 8k; #v2
    gzip_http_version 1.1;

    gzip_disable "MSIE [1-6].(?!.*SV1)";
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Fast cgi
    ##

  #  fastcgi_intercept_errors on;
  #  fastcgi_ignore_client_abort on;
  #  fastcgi_buffers 8 16k;
   # fastcgi_buffer_size 32k;
 #   fastcgi_read_timeout 120;
    #fastcgi_index  index.php;
#
  #  limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;


    ##
    # Virtual Host Configs
    ##

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

可用的站点

map $host $wp_dir_id {
        .my-website-with-id-1-in-wordpress.com      1;
        site2.com      2;
        site3.com      3;
        site4.com      4;
}
server {
        ## Ports
        listen          80;

        ## server name
        # . acts as wildcard

        server_name     .my-website-with-id-1-in-wordpress.com;

        ## root

        root            /var/www/;

        ## global rewrites
        # WordPress Network sites files (map is above)

        if ( $wp_dir_id != 1 )
        {
                rewrite ^/files/(.*)$ /wp-content/blogs.dir/$wp_dir_id/files/$1 last;
        }
        # fallback if site is not mapped
        if ( $wp_dir_id = 1 )
        {
                rewrite ^(.*)/files/(.*)$ /wp-includes/ms-files.php?file=$2 last;
        }
        ## locations

        location / {
                # enable browser cache for images
                # not location, because this applies for PHP served images as well in WP Network
                if ( $uri ~ \.(ico|gif|jpg|jpeg|png)$  ) {
                        expires 31d;
                        add_header Pragma public;
                        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
                }

                # enable browser cache for css / js
                # not location, because this applies for PHP served files as well in WP Network
                if ( $uri ~ \.(css|js)$  ) {
                        expires 7d;
                        add_header Pragma public;
                        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
                }
                # default uri
                try_files $uri $uri/ @rewrites;
        }
        # rewrite rules
        location @rewrites {
                rewrite ^(.*)$ /index.php?q=$1 last;
        }
        ## hide files starting with .
        location ~ /\. {
                deny all;
                log_not_found off;
        }
        ## enable nginx status screen, optional
        location /nginx_status {
                stub_status on;
        }
        ## pass to PHP5-FPM server in the background
        location ~ .php {
                fastcgi_param   QUERY_STRING            $query_string;
                fastcgi_param   REQUEST_METHOD          $request_method;
                fastcgi_param   CONTENT_TYPE            $content_type;
                fastcgi_param   CONTENT_LENGTH          $content_length;
                fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
                fastcgi_param   REQUEST_URI             $request_uri;
                fastcgi_param   DOCUMENT_URI            $document_uri;
                fastcgi_param   DOCUMENT_ROOT           $document_root;
                fastcgi_param   SERVER_PROTOCOL         $server_protocol;
                fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
                fastcgi_param   SERVER_SOFTWARE         nginx;
                fastcgi_param   REMOTE_ADDR             $remote_addr;
                fastcgi_param   REMOTE_PORT             $remote_port;
                fastcgi_param   SERVER_ADDR             $server_addr;
                fastcgi_param   SERVER_PORT             $server_port;
                fastcgi_param   SERVER_NAME             $server_name;
                # PHP only, required if PHP was built with --enable-force-cgi-redirect
                fastcgi_param   REDIRECT_STATUS         200;
                fastcgi_index                           index.php;
                fastcgi_connect_timeout                 60;
                fastcgi_send_timeout                    180;
                fastcgi_read_timeout                    180;
                fastcgi_buffer_size                     128k;
                fastcgi_buffers                         4       256k;
                fastcgi_busy_buffers_size               256k;
                fastcgi_temp_file_write_size            256k;
                fastcgi_intercept_errors                on;
                fastcgi_ignore_client_abort             on;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                   #fastcgi_pass    127.0.0.1:9000;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

答案1

我可以部分回答,因为经过一两天的阅读

1) APC 仍然像上图链接中那样碎片化。我会尝试找到它,并找出造成碎片化的原因,但最大的碎片文件是 batcache 和 apc wordpress 插件。

2) javascript 没有被 gzip 压缩,因为它是作为 application/javascript 发送的,而且我发现我的 cfg 中已经有两个 javascript,包括 text/javascript(我一直以为默认是 javascript)。

因此现在服务器上的所有数据都经过了 gzimed。因此,在我将 application/javascript 添加到问题中第一个代码块中以“gzip_types”开头的行后,javascript 开始工作。

3) 由于我没有子域多站点的所有 nginx 重写规则(主要有 3 条规则可获得漂亮的永久链接),因此 index.php 没有被重写。然而,这导致了另一个问题的出现,我将为此提出一个新问题。

这是三行重写的内容,我只有最后一句

rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
rewrite ^/(.*)$ /index.php?q=$1 last;

相关内容