最新在线看的黄网|伊人久久久久久久网站|日本a视频专区二|欧美A级无码毛片|有扫五av在线播放|好屌日aV在线播放|内射福利视频导航|极品少妇一区二区视频|无吗在线一区播放|性爱黄色视频不卡

您的位置:首頁 > wordpress

WordPress使用Nginx+memcached全站頁面緩存加速
wordpress 2024-03-03編輯:深圳網(wǎng)站建設(shè)閱讀( WordPress 緩存 全站

Memcached是個好東西 它可以?由于頁面是緩存在內(nèi)存里,所以減少了系統(tǒng)的I/O操作??梢灾苯永肕emcached的分布式特性??梢灾苯永镁彺娴倪^期時間,方便對頁面的過期時間進(jìn)行處理。

網(wǎng)上找了很多教程 都不適用于wordpress 于是我經(jīng)網(wǎng)上的腳本 自己改了一個

注意事項!!?memcached是多核處理的 如果你是單核的服務(wù)器 在配上這個 會相當(dāng)?shù)目?甚至?xí)礄C(jī) 我之前出過了很多問題 所以我現(xiàn)在僅能把教程寫出來 而我用了redis /哭;w;

原理

Nginx內(nèi)置了Memcached模塊memcached_module
它可以從memcached中讀取內(nèi)容后直接輸出,后續(xù)的請求不再經(jīng)過如php-fpm、django應(yīng)用程序處理,大大的提升動態(tài)頁面的速度。nginx只負(fù)責(zé)從memcached中讀取數(shù)據(jù),要往memcached寫入數(shù)據(jù)還得需要后臺的應(yīng)用程序來完成,主動的將要緩存的頁面緩存到memcached中,然后通過404重定向到后端去處理的。

memcached的key可以通過memcached_key變量來設(shè)置,如以$uri。如果命中,那么直接輸出內(nèi)容,沒有命中就意味著nginx需要從應(yīng)用程序請求頁面。同時,我們還希望該應(yīng)用程序?qū)㈡I值對寫入到memcached,以便下一個請求可以直接從memcached獲取。
如果鍵值不存在,nginx將報告not found錯誤。最好的方法是使用error_page指定和location請求處理。同時包含"Bad
Gateway"錯誤和"Gateway Timeout"錯誤,如:error_page 404 502 504 = @app;。

WordPress應(yīng)用實例

user  www www;
worker_processes auto;
error_log  /www/wwwlogs/nginx_error.log  crit;
pid        /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;  events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
		#include luawaf.conf;

		include proxy.conf;

        default_type  application/octet-stream;

        server_names_hash_bucket_size 512;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

	    keepalive_timeout  75s;
	    keepalive_requests 10000;
        
        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 512k;
	fastcgi_intercept_errors on;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 3;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css text/xml application/xml image/jpeg image/gif image/png application/x-httpd-php;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6].";

        limit_conn_zone $binary_remote_addr zone=perip:10m;
		limit_conn_zone $server_name zone=perserver:10m;

        server_tokens off;
        access_log off;
        
#memcache servers load balanced
	upstream memcached {
        server     127.0.0.1:11211 weight=5 max_fails=3  fail_timeout=30s;
		keepalive 1024;
		}
#fastcgi - little load balancer
	upstream phpbackend{
		server     127.0.0.1:9000 weight=5 max_fails=5  fail_timeout=30s;
		}
server {
    listen 80;
    root  /www/server/wwwroot;
    server_name www.bt.cn;
    index index.html index.htm index.php;
    include enable-php.conf;
    client_body_timeout  1460;
    client_header_timeout 1460;
    send_timeout 1460;
    client_max_body_size 10m;
    keepalive_timeout 1300;

    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

	location ~* .(jpg|png|gif|css|js|swf|flv|ico)$ {
	    expires max;
	    tcp_nodelay off;
	    tcp_nopush on;
    }
    location / {
		
        try_files $uri $uri/ @handler;
        expires 30d;
    }
   location @handler {
	rewrite / /index.php;
    }

    location ~ .php$ {
        if (!-e $request_filename) { 
            rewrite / /index.php last; 
        }  
        expires        off; ## Do not cache dynamic content
        default_type       text/html; charset utf-8;
        if ($request_method = GET) {
            set $memcached_key $request_uri;
            memcached_pass     memcached;
            error_page         404 502 = @cache_miss;
            add_header x-header-memcached true;
		}
		if ($request_method != GET) {
			fastcgi_pass phpbackend;
		}
    }
    location @cache_miss {
        # are we using a reverse proxy?
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_max_temp_file_size 0;
        
        #configure fastcgi
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_send_timeout  5m;
        fastcgi_read_timeout 5m;
        fastcgi_connect_timeout 5m;
        fastcgi_buffer_size	256k;
        fastcgi_buffers	4	512k;
        fastcgi_busy_buffers_size	768k; 
        fastcgi_param  PHP_VALUE "memory_limit = 32M";
        fastcgi_param  PHP_VALUE "max_execution_time = 18000";
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /. {
		deny all;
	}
}

}

寶塔面板

首先在nginx總配置中連接memcached 在http{ }字段中添加

#memcache servers load balanced
	upstream memcached {
        server     127.0.0.1:11211 weight=5 max_fails=3  fail_timeout=30s;
		keepalive 1024;
		}
#fastcgi - little load balancer
	upstream phpbackend{
		server     127.0.0.1:9000 weight=5 max_fails=5  fail_timeout=30s;
		}

然后在網(wǎng)站中添加配置

網(wǎng)站-你的網(wǎng)站-設(shè)置-配置文件中 的 最后一個“}”前添加

  client_body_timeout  1460;
    client_header_timeout 1460;
    send_timeout 1460;
    client_max_body_size 10m;
    keepalive_timeout 1300;

    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

    location ~* .(jpg|png|gif|css|js|swf|flv|ico)$ {
	    expires max;
	    tcp_nodelay off;
	    tcp_nopush on;
    }
    location / {
		
        try_files $uri $uri/ @handler;
        expires 30d;
    }
   location @handler {
	rewrite / /index.php;
    }

    location ~ .php$ {
        if (!-e $request_filename) { 
            rewrite / /index.php last; 
        }  
        expires        off; 
        default_type       text/html; charset utf-8;
        if ($request_method = GET) {
            set $memcached_key $request_uri;
            memcached_pass     memcached;
            error_page         404 502 = @cache_miss;
            add_header x-header-memcached true;
		}
		if ($request_method != GET) {
			fastcgi_pass phpbackend;
		}
    }
    location @cache_miss {

        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_max_temp_file_size 0;
        

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_send_timeout  5m;
        fastcgi_read_timeout 5m;
        fastcgi_connect_timeout 5m;
        fastcgi_buffer_size	128k;
        fastcgi_buffers	4	256k;
        fastcgi_busy_buffers_size	512k; 

        fastcgi_param  PHP_VALUE "memory_limit = 32M";
        fastcgi_param  PHP_VALUE "max_execution_time = 18000";
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /. {
		deny all;
	}

說明

這個是我改過的版本 理應(yīng)寶塔面板下的Wordpress都可以用

如果提示你 什么什么錯誤 那你應(yīng)該檢查一下 你的Nginx剛開始時是否是 編譯安裝方法 如果你是極速安裝的方法 請重裝成編譯安裝

服務(wù)范圍:WordPress搭建、WordPress主題開發(fā)、WordPress二次開發(fā)、WordPress插件開發(fā)
其它服務(wù):網(wǎng)站建設(shè)、企業(yè)郵箱、數(shù)字證書ssl、400電話、
技術(shù)標(biāo)簽:企業(yè)網(wǎng)站、外貿(mào)網(wǎng)站、外貿(mào)商城、其它問題
聯(lián)系方式:電話:13714666846 微信同號

企業(yè)網(wǎng)站定制

企業(yè)網(wǎng)站定制 根據(jù)企業(yè)需求,量身定制設(shè)計

企業(yè)網(wǎng)站定制:2800元起
添加微信 請說明來意
聯(lián)系我們
站內(nèi)搜索 MORE+

24小時服務(wù)熱線 0755-29765948
  • 地址:深圳市羅湖區(qū)人民北路2033號206
  • 電話:0755-29765948 傳真:82256610
  • 手機(jī):13714666846 18948334877
  • 郵箱:gong@ew35.com 164761418@qq.com
  • 粵ICP備14049207號
創(chuàng)意化數(shù)字品牌整合網(wǎng)絡(luò)營銷
營銷網(wǎng)站讓你坐等商機(jī)坐傭客戶,Rss

版權(quán)所有:深圳市網(wǎng)商在線科技有限公司

版權(quán)所有:深圳市網(wǎng)商在線科技有限公司
友情連接link: