Nginx http_sub_module and proxy_module solve Google APIs problems

Source: Internet
Author: User

Due to network problems, some static files may not be directly accessed by users. I provide a solution here.

I found that, for some reason, the static class libraries and font styles referenced by Google APIs in my blog cannot be correctly loaded. For example:

Https: // fonts.googleapis.com/css? Family = Open + Sans % 3A300italic % 2C400italic % 2C600italic % 2C300% 2C400% 2C600 & subset = latin % 2Clatin-ext
Https: // ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js
Websites like this are often unable to be correctly loaded, which causes some functions of my blog (WordPress 4.4 +) to be abnormal and the background is very slow to open.

I understand that Nginx has a feature called string subsitute, that is, string replacement, that is, a brainless string replacement before the content is returned to the browser. So we can use this feature,
Some domestic IT manufacturers with a bit of conscience have provided corresponding CDN images, as long as they have no brains to replace the server address of the failed access URL with the CDN address of the large factory.

Sub_filter_types text/xml text/css text/javascript;
Sub_filter 'https: // fonts.googleapis.com ''http: // ajax.useso.com ';
Sub_filter 'https: // ajax.googleapis.com ''http: // fonts.useso.com ';
Sub_filter_once off;
In this way, you can easily solve the problem. In the above example, CDN provided by digital companies is a great help.

Note that sub_filter versions earlier than Nginx 1.9.4 cannot be written twice. I don't know how to think about it. Fortunately, you can write multiple latest versions.

Basically, this has solved most of the problems for Chinese web users. But if your website unfortunately uses HTTPS, it will be silly, because of digital companies, CDN images that support HTTPS are not provided. At least in this article, it is not supported.

I have found the only domestic image that supports HTTPS on the internet. It is an additional service in the blog system of the freshman group of students in the Chinese section. Although the idea is good, it is very unstable, I can't load it from time to time, and it's not as reliable as my personal blog.

So I thought that since this request can be replaced with any other server, it can be replaced with my own server. In this way, I will use the proxy_module feature to initiate a proxy_pass proxy, I did not solve it all. After trying it, it was really easy and smooth. After learning Nginx for a long time, I finally integrated it and realized a small function, eliminating my own little troubles.

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.