wordpress - nginx 反代 Varnish 走 Https ,WP后臺(tái) ‘您沒有足夠的權(quán)限訪問該頁面。’
問題描述
問題:
最近研究 Varnish 上 Https,目前都是 nginx:443 反代 varnish:80 后端 nginx:80。所以我也走的找個(gè)。 不過弄好以后。前臺(tái)都是正常的,打開飛快,但是后臺(tái) wp-admin 什么地方都是 ‘您沒有足夠的權(quán)限訪問該頁面。’ WP 重新安裝一遍也還是如此。
Nginx:443 的反代規(guī)則
location ~ / { proxy_pass http://127.0.0.1:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-SSL on; proxy_hide_header Vary; proxy_redirect off;}
Varnish 的規(guī)則
vcl 4.0; # 后端服務(wù)器配置backend default { .host = '127.0.0.1'; # 后端服務(wù)器的域名或 IP .port = '8080'; # 端口 .connect_timeout = 600s; .first_byte_timeout = 600s; .between_bytes_timeout = 600s; .max_connections = 128;} acl purge { 'localhost'; '127.0.0.1';} # vcl_recv 表示 Varnish 收到客戶端請(qǐng)求的時(shí)候sub vcl_recv { # 當(dāng) HTTP 方法是 Purge 時(shí),檢查來源 IP,如果 IP 有效,則進(jìn)行 Purge 操作 if (req.method == 'PURGE') { if (!client.ip ~ purge) { return(synth(405, 'This IP is not allowed to send PURGE requests.')); } return (purge); } # 不緩存有密碼控制的內(nèi)容和 Post 請(qǐng)求 if (req.http.Authorization || req.method == 'POST') { return (pass); } # 不緩存管理員頁面和預(yù)覽頁面 if (req.url ~ 'wp-(login|admin)' || req.url ~ 'preview=true') { return (pass); } # 不緩存已登錄用戶的內(nèi)容 if (req.http.Cookie ~ 'wordpress_logged_in_') { return (pass); } # 清除 cookie,因?yàn)?WordPress 會(huì)根據(jù)用戶 cookie 在評(píng)論框中直接輸出昵稱 unset req.http.cookie; # 進(jìn)行 hash 操作,見下面的定義 return (hash);} sub vcl_pipe {return (pipe);} sub vcl_pass {return (fetch);} # 定義用于緩存的鍵sub vcl_hash { # 這里使用 URL 做為鍵,如果是多域名站點(diǎn),則需要使用 req.http.host + req.url hash_data(req.url); return (lookup);} # 處理后端服務(wù)器的響應(yīng)sub vcl_backend_response { # 刪掉一些沒有用的項(xiàng) unset beresp.http.X-Powered-By; unset beresp.http.x-mod-pagespeed; # 對(duì)于圖片之類的靜態(tài)內(nèi)容,刪掉 cookie 并且設(shè)置瀏覽器緩存時(shí)間為一個(gè)月 if (bereq.url ~ '.(css|js|png|gif|jp(e?)g|swf|ico|txt|eot|svg|woff)') { unset beresp.http.cookie; set beresp.http.cache-control = 'public, max-age=2700000'; } # 不緩存管理員頁面和預(yù)覽頁面 if (bereq.url ~ 'wp-(login|admin)' || bereq.url ~ 'preview=true') { set beresp.uncacheable = true; set beresp.ttl = 30s; return (deliver); } # 這一段很重要,在用戶提交評(píng)論的同時(shí),立即清空該頁面的緩存,這樣用戶可以加載到最新的頁面 if (bereq.url == '/wp-comments-post.php') { ban('req.url == ' + regsub(beresp.http.Location, '^http(s)?://bb.mf8.biz(/.*/)$ } # 不緩存 Post 請(qǐng)求和有密碼的內(nèi)容 if ( bereq.method == 'POST' || bereq.http.Authorization ) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver); } # 只緩存正常的響應(yīng)和 404 if ( beresp.status != 200 && beresp.status != 404 ) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver); } unset beresp.http.set-cookie; # 默認(rèn)緩存時(shí)間是 24 小時(shí) set beresp.ttl = 24h; set beresp.grace = 30s; return (deliver);} sub vcl_deliver { return (deliver);}sub vcl_init {return (ok);}sub vcl_fini {return (ok);}
問題解答
回答1:已經(jīng)解決,整理如下:https://www.mf8.biz/varnish-wordpress-make-fast-2/
