Hướng dẫn cấu hình Super Cache trên aaPanel

22
0

Xin chào tất cả các bạn đang xem blog của mình. Vừa rồi mình có xem một bài post của một tác giả trên aaPanel thì có giới thiệu cấu hình WordPress + WP Super Cache + Nginx với máy chủ VPS có thông số tài nguyên là (VPS 1 СPU/1 GB RAM/12 GB SSD NVMe) sau khi cấu hình thì đã chịu được 500 clients per second test (loader.io) và bên dưới là ảnh test.

1604660578 130292 screenshot wp a load test by loaderio 20201106 12 54 37

Quả thực rất tuyệt vời khi điều đó là chính xác. Mình đã test thử trên website của mình và viết lại bài viết này để chia sẻ để các bạn cách thực hiện. Và sau đây mời các bạn xem qua nhé.

Bước 1: Cấu hình NGINX

Đầu tiên bạn hãy cấu hình NGINX với các rule của super cache. Bạn có thể xem file cấu hình tại link bên dưới hoặc file mẫu của mình.

  • Xem file cấu hình Nginx Super cache rule tại đây

Bạn truy cập Website => Chọn website => URL rewrite để bắt đầu thiết lập.

Screenshot 2021 06 26 at 19.00.37

Bên dưới là file cấu hình mình để sẵn cho các bạn để copy

# WP Super Cache rules.
# Designed to be included from a 'wordpress-ms-...' configuration file.
 
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';
}
 
# START MOBILE
# Mobile browsers section to server them non-cached version. COMMENTED by default as most modern wordpress themes including twenty-eleven are responsive. Uncomment config lines in this section if you want to use a plugin like WP-Touch
# if ($http_x_wap_profile) {
#        set $cache_uri 'null cache';
#}
 
#if ($http_profile) {
#        set $cache_uri 'null cache';
#}
 
#if ($http_user_agent ~* (2.0 MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo Wii|Nitro|Nokia|Opera Mini|Palm|PlayStation Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915 Obigo|LGE VX|webOS|Nokia5800)) {
 #       set $cache_uri 'null cache';
#}
 
#if ($http_user_agent ~* (w3c |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda |xda-)) {
  #      set $cache_uri 'null cache';
#}
#END MOBILE
 
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
        try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;
}    

Sau khi đã cấu hình NGINX hoàn tất tiếp theo thực hiện cấu hình trên Plugin Super Cache

Bước 2: Cấu hình Super Cache

Bạn hãy cài Plugin WP Super Cache vào webiste WordPress của bạn và thực hiện cấu hình như sau.

Bạn truy cập vào Cài đặt (Settings) => WP Super Cache và chọn dòng Easy. Phần Caching bạn tick vào Caching On và chọn Update Status để áp dụng.

Screenshot 2021 06 26 at 18.54.37

Tiếp theo là cấu hình nâng cao.

Mục Cache Delivery Method bạn chọn  Expert. Và những tuỳ chọn khác bạn hãy chọn dòng nào có chữ (Recommended) là được. Khi đã chọn xong bạn tick Update Status để áp dụng.

Screenshot 2021 06 26 at 18.56.26

Tiếp đến phần Preload bạn chọn như ảnh sau đó Save Settings để lưu các thiết lập nhé.

Screenshot 2021 06 26 at 19.09.46

Cảm ơn các bạn đã theo dõi bài Hướng dẫn cấu hình Super Cache trên aaPanel của mình. Chúc các bạn thực hiện thành công.

Đỗ Trung Quân
WRITTEN BY

Đỗ Trung Quân

Nguồn nội dung này đến từ Website DoTrungQuan.info

Trả lời