wordpress - nginx 反代 Varnish 走 Https ,WP后臺 ‘您沒有足夠的權限訪問該頁面。’
問題描述
問題:
最近研究 Varnish 上 Https,目前都是 nginx:443 反代 varnish:80 后端 nginx:80。所以我也走的找個。 不過弄好以后。前臺都是正常的,打開飛快,但是后臺 wp-admin 什么地方都是 ‘您沒有足夠的權限訪問該頁面。’ WP 重新安裝一遍也還是如此。
Nginx:443 的反代規則
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 的規則
vcl 4.0; # 后端服務器配置backend default { .host = '127.0.0.1'; # 后端服務器的域名或 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 收到客戶端請求的時候sub vcl_recv { # 當 HTTP 方法是 Purge 時,檢查來源 IP,如果 IP 有效,則進行 Purge 操作 if (req.method == 'PURGE') { if (!client.ip ~ purge) { return(synth(405, 'This IP is not allowed to send PURGE requests.')); } return (purge); } # 不緩存有密碼控制的內容和 Post 請求 if (req.http.Authorization || req.method == 'POST') { return (pass); } # 不緩存管理員頁面和預覽頁面 if (req.url ~ 'wp-(login|admin)' || req.url ~ 'preview=true') { return (pass); } # 不緩存已登錄用戶的內容 if (req.http.Cookie ~ 'wordpress_logged_in_') { return (pass); } # 清除 cookie,因為 WordPress 會根據用戶 cookie 在評論框中直接輸出昵稱 unset req.http.cookie; # 進行 hash 操作,見下面的定義 return (hash);} sub vcl_pipe {return (pipe);} sub vcl_pass {return (fetch);} # 定義用于緩存的鍵sub vcl_hash { # 這里使用 URL 做為鍵,如果是多域名站點,則需要使用 req.http.host + req.url hash_data(req.url); return (lookup);} # 處理后端服務器的響應sub vcl_backend_response { # 刪掉一些沒有用的項 unset beresp.http.X-Powered-By; unset beresp.http.x-mod-pagespeed; # 對于圖片之類的靜態內容,刪掉 cookie 并且設置瀏覽器緩存時間為一個月 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'; } # 不緩存管理員頁面和預覽頁面 if (bereq.url ~ 'wp-(login|admin)' || bereq.url ~ 'preview=true') { set beresp.uncacheable = true; set beresp.ttl = 30s; return (deliver); } # 這一段很重要,在用戶提交評論的同時,立即清空該頁面的緩存,這樣用戶可以加載到最新的頁面 if (bereq.url == '/wp-comments-post.php') { ban('req.url == ' + regsub(beresp.http.Location, '^http(s)?://bb.mf8.biz(/.*/)$ } # 不緩存 Post 請求和有密碼的內容 if ( bereq.method == 'POST' || bereq.http.Authorization ) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver); } # 只緩存正常的響應和 404 if ( beresp.status != 200 && beresp.status != 404 ) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver); } unset beresp.http.set-cookie; # 默認緩存時間是 24 小時 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:已經解決,整理如下:https://www.mf8.biz/varnish-wordpress-make-fast-2/
