Configure nginx to filter out poor access and increase squid hit rate

Source: Internet
Author: User
Author: Ayou.1. Access to static content with question marks, for example, http: www.7jiejie.com? Abc, such a request will go directly to the backend server through squid cache and save the cache in squid, resulting in pressure and memory waste. Add filtering rules for html files and home pages to the nginx server to solve this problem. This rule determines the Home Page

Author: Ayou

1. Access to static content with question marks

Like http://www.7jiejie.com? Abc, such a request will pass through squIdCache directly to the backend server and save the cache in squid, resulting in pressure and memory waste.

Add filtering rules for html files and home pages to the nginx server to solve this problem. This rule judges the files ending with the home page and html, jpg, and gif. If there are? The error 403 is thrown, which is received by error_page and jumped to the correct address with 302.

LoCatIon ~ * (.Html $) | (^/$) | (.jpg $) | (.gif $ ){
Proxy_pass http://www.7jiejie.com;
If ($ is_args)
{
Return 403;
Error_page 403 = 200 $ scheme: // $ host $ uri;
}
}

This method is not perfect either. In the test, try to use the reWriteBut the original $ args is retained after rewrite? . In addition, if the url contains Chinese characters, the jump will fail, so make sure that the url does not contain Chinese characters, including url_eNcOde result.

2. Send a POST request to static content

Such requests also pass through squid, but do not cache content in squid.

Draw a Sequence Based on Huludao. The following configuration can be solved:
Location ~ * (.Html $) | (^/$) | (.jpg $) | (.gif $ ){
Proxy_pass http://www.7jiejie.com;
If ($ request_method = POST ){
Return 403;
Error_page 403 = 200 $ scheme: // $ host $ uri;
}
}

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.