กรุณาปิด โปรแกรมบล๊อกโฆษณา เพราะเราอยู่ได้ด้วยโฆษณาที่ท่านเห็น
Please close the adblock program. Because we can live with the ads you see


วิธีการทํา Directadmin + XenForo 2.x + Nginx fastcgi_cache full page guest caching

Directadmin + XenForo 2.x + Nginx fastcgi_cache full page guest caching.

เนื้อหานี้ต้นฉบับอยู่ที่ xenforo offical site ครับ


แต่ทางผมนำมาดัดแปลงเพื่อให้ใช้งานกับ directadmin ได้ครับ ที่สำคัญเลยคือต้องสามารถใช้ shell ได้ด้วย

นันคือเป็น root นั้นเอง ก็คือ เจ้าของเครื่องหรือ vps ครับ อ้อย้ำนะครับ ต้องเป็น Nginx webserver นะครับ

เริ่มจากทำตามไกด์เลยครับ
Nginx includes a FastCGI module which has directives for caching dynamic content that are served from the PHP backend. Setting this up removes the need for additional page caching solutions like reverse proxies (think Varnish) or application specific plugins. Content can also be excluded from caching based on the request method, URL, cookies, or any other server variable.
  • 1st: ต้องติดตั้ง Addon, เพราะจะมีคุกกี้ถาวรสำหรับผู้ใช้เข้าสู่ระบบ.
  • 2nd: เพิ่มโค๊ดต่อไปนี้ใน Nginx config ภายใต้แทค http { บล๊อก ใน directadmin เราจะเพิ่มในไฟล์ /etc/nginx/nginx-incloudes.conf นะครับเพราะเป้นไฟล์เปล่าๆและถูก incloud ไว้แล้วตามที่เราต้องการพอดี
จะปรับเปลี่ยนไม่ได้ตามต้องการเพราะค่าดีฟอลด์คุกกี้ของ xenforo คือ xf_.
NGINX:
### Start FastCGI Cache
map $http_cookie $nocachecookie {
default 0;
~xf_user 1;
~xf_style_id 1;
~xf_lscxf_logged_in 1;
}
map $request_uri $nocacheuri {
default 0;
~^/register 1;
~^/login 1;
~^/misc/style 1;
}
fastcgi_cache_path /var/run/nginx_fastcgi_cache levels=1:2 keys_zone=fastcgicache:512m inactive=30m;
### End FastCGI Cache
  • 3rd: จากตัวอย่างนี้ example, เราจะเพิ่มโค๊ดด้านล่างนี้ต่อจาก include /etc/nginx/fastcgi_params; ในไฟล์ /usr/local/directadmin/data/users/username/nginx_php.conf
NGINX:
### fastcgi_cache start
fastcgi_cache_methods GET;
fastcgi_cache_key $host$request_method$request_uri;
fastcgi_cache_lock on;
fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache fastcgicache;
fastcgi_no_cache $nocachecookie $nocacheuri;
fastcgi_cache_bypass $nocachecookie $nocacheuri;
fastcgi_cache_valid 200 301 302 303 404 5m;
add_header X-Cache-Status $upstream_cache_status;
### fastcgi_cache end
  • 4th: เซพแล้วทำการ restart Nginx and PHP-FPM.
จากนั้นทำการทดสอบเข้าเว็บไซต์ดูครับ ถ้าเป็น guest ในหน้า network console จะแสดง x-cache-status: HIT

แสดงว่าระบบแคชทำงานแล้วครับ #icafezone #xenforo 👍

ปล. การตั้งค่าเวลาในการเก็บแคช ให้แก้ไขที่
Code:
fastcgi_cache_valid 200 301 302 303 404 5m;
ตรง 5m = 5 นาที ให้แก้ตามที่ต้องการเลยครับ
 
แก้ไขล่าสุดเมื่อ:

Similar threads

  • บทความ บทความ
ตอบ
2
อ่าน
157
  • ปักหมุด
  • บทความ บทความ
ตอบ
0
อ่าน
349
    • Like
  • บทความ บทความ
ตอบ
0
อ่าน
385
  • บทความ บทความ
ตอบ
0
อ่าน
867
  • บทความ บทความ
ตอบ
2
อ่าน
1K



กรุณาปิด โปรแกรมบล๊อกโฆษณา เพราะเราอยู่ได้ด้วยโฆษณาที่ท่านเห็น
Please close the adblock program. Because we can live with the ads you see
ด้านบน ด้านล่าง