Nginx cache uses "Go"

Source: Internet
Author: User
Tags nginx server


1. Compiling the installation
Install the Cache_purge module, you can refer to my written: http://bbs.linuxtone.org/thread-6875-1-1.html
Nginx Server configuration:

  1. Server
  2. {
  3. Listen 80;
  4. server_name 54yancheng.com www.54yancheng.com;
  5. #purge Cache files
  6. Location ~/purge (/.*)
  7. {
  8. #设置只允许指定的IP或IP段才可以清除URL缓存, add the IP address of your squid server.
  9. Allow 114.244.0.0/16;
  10. Allow 192.168.0.0/16;
  11. Deny all;
  12. Proxy_cache_purge Cache_one $host $1$is_args$args;
  13. Error_page 405 =200/purge$1; 405 errors that occur when #处理squidclient purge
  14. }
  15. #用if判断 $request _method is purge, go to the/purge/location to deal with it.
  16. if ($request _method = "PURGE") {
  17. Rewrite ^ (. *) $/purge$1 last;
  18. }
  19. #pass files
  20. Location/
  21. {
  22. Proxy_set_header Host $host;
  23. Proxy_set_header x-forwarded-for $remote _addr;
  24. Proxy_pass Http://54yancheng;
  25. }
  26. #cache files
  27. Location ~. *\. (GIF|JPG|JPEG|PNG|BMP|SWF|JS|CSS) $
  28. {
  29. Add_header X-cache hit_from_www.54yancheng.com;
  30. Proxy_cache Cache_one;
  31. Proxy_cache_valid 304 12h;
  32. Proxy_cache_valid 301 302 1m;
  33. Proxy_cache_valid any 1m;
  34. Proxy_cache_key $host $uri$is_args$args;
  35. Proxy_set_header Host $host;
  36. Proxy_set_header x-forwarded-for $remote _addr;
  37. Proxy_pass Http://54yancheng;
  38. Expires 365d;
  39. Access_log off;
  40. }
  41. #web Log
  42. #access_log off;
  43. Access_log/data/logs/access_www.54yancheng.com.log combined;
  44. }
Copy Code


2.squidclient Cleanup Example:

    1. # squidclient-h 192.168.0.111-p 80-m purge-v http://www.54yancheng.com/ads/6739984.gif
    2. Headers: ' PURGE http://www.54yancheng.com/ads/6739984.gif http/1.0
    3. Accept: */*
    4. http/1.1 OK
    5. Server:nginx
    6. Date:mon, Sep 03:05:02 GMT
    7. Content-type:text/html
    8. content-length:290
    9. Connection:close
    10. <body bgcolor= "White" >
    11. <center>
    12. <br>key:www.54yancheng.com/ads/6739984.gif
    13. <br>path:/data/cache/nginx_cache/3/6d/e70fbe8e578b27440e8f2e60269966d3
    14. </center>
    15. </body>
Copy Code


3. Script inventory multiple configurations of Nginx cache, and output status
In the actual production, the business uses more than one nginx cache to do load balancing, this script is to realize the function of eliminating the cahce of the multi-nginx server.

    1. #!/bin/sh
    2. #利用squidclient的PURGE清除多nginx服务器cache脚本
    3. #bbs: www.linuxtone.org
    4. #by: Hamgua
    5. echo "Nginx purge $"
    6. echo "----------------------------"
    7. For i in {1..3};d o
    8. echo "host:192.168.0. $i"
    9. echo "Status: '/usr/local/squid2/bin/squidclient-h 192.168.0. $i-P 80-m purge-v" 2>&1 |grep "^<center>" |a Wk-f ' [><] ' {print $} ' "
    10. echo "----------------------------"
    11. Done
Copy Code

Examples of script use:

    1. #./purge.sh Http://www.54yancheng.com/ads/6739984.gif
Copy Code
    1. Nginx Purge Http://www.54yancheng.com/ads/6739984.gif
    2. ----------------------------
    3. host:192.168.0.1
    4. Status:successful Purge
    5. ----------------------------
    6. host:192.168.0.2
    7. status:404 not Found
    8. ----------------------------
    9. host:192.168.0.3
    10. status:404 not Found
    11. ----------------------------
Copy Code



Reference article:
Installation configuration Reference I wrote: http://bbs.linuxtone.org/thread-6875-1-1.html
Squidclient Remove Nginx Cache, refer to Sudone's article: http://sudone.com/nginx/nginx_cache_purge.html
Linuxtone Web server Nginx section: http://bbs.linuxtone.org/forumdisplay.php?fid=22&filter=type&typeid=1
Banquet with Nginx Proxy_cache cache function instead of squid[original] http://blog.s135.com/nginx_cache/

Nginx cache uses "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.