Focus on cloud service provider activities
Notes on website operation and maintenance

In actual combat, Nginx is used to realize the anti proxy acceleration website to solve the problem of instability of overseas VPS lines

If we have users who use overseas VPS to build Chinese websites, we will definitely feel the instability of the lines, and even a lot of packet loss, especially for telecom broadband users from night to midnight. Whatever the reason, we must consider solving it by ourselves, either choose Asian lines or domestic servers, or adopt the reverse generation acceleration method to speed up its website.

 In actual combat, Nginx is used to realize the anti proxy acceleration website to solve the problem of instability of overseas VPS lines

In this article, Lao Zuo tried to use NGINX to achieve the goal of anti generation acceleration website. He had seen many similar articles before, but did not practice them. So this afternoon, he had a little time to actually operate it again. The same will be recorded in the form of pictures and text, so that friends in need can view and use it.

First, install the NGINX environment

Here, we can use the method of compiling the source directly to install NGINX, or we can directly use the LNMP one click package of JunBrother to install the system environment with NGINX environment( Basic Tutorial Directory of LNMP One click Installation Package )。

Second, add a site profile

A - You can use the LNMP environment package vhost to add sites here, or you can manually add the virtual host site configuration in the nginx environment.

vi /usr/local/nginx/conf/vhost/ example.com .conf

gules example.com Part is our site domain name.

B - Set directory permissions

mkdir /home/cache/path -p
mkdir /home/cache/temp
chmod 777 -R /home/cache

Set the cache directory permission storage path.

C - Configure nginx conf file

proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout  5;
proxy_buffer_size 16k;
proxy_buffers  4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/cache/temp;
#Temporary file directory
proxy_cache_path /home/cache/path levels=1:2 keys_zone=cache_one:5m inactive=7d max_size=1g;
#5m is the memory occupation, 1g is the maximum hard disk occupation, and cache_one is the cache name. If necessary, modify it accordingly.

You need to configure the cache corresponding to the path in B. Generally, you can directly use the default and do not modify it.

D - Configuration example.com .conf

listen 80;
server_name example.com www.example.com;
#Bound domain name
index index.php;
#Default Home Page
access_log off;
#Off Close log
location / {
proxy_cache_key "$scheme://$host$request_uri";
#Cache key rules are used to automatically clear the cache.
proxy_cache cache_one;
#Cache name, the same as previously defined
proxy_cache_valid 200 304 3h;
proxy_cache_valid 301 3d;
proxy_cache_valid any 10s;
#200 304 state cache for 3 hours
301 State cache for 3 days
Other state cache (such as 502 404) 10 seconds
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#Pass guest ip to the backend
proxy_set_header Referer http://example.com ;
#Mandatory definition of referer, which will be used for program verification and judgment
proxy_set_header Host $host;
#Define host header
proxy_pass http://1.2.3.4 ;
#Specify the back-end IP, which can be added with ports
#proxy_cache_use_stale invalid_header error timeout http_502;
#Enable expiration caching when the backend is in error, timeout, or 502 status, and use it with caution.
}
}

When resolving domain names, point to the front-end IP. We can learn the annotation part, and then modify it according to our own needs.

Third, restart NGINX to take effect

/etc/init.d/nginx restart

Through the above four steps, we can use nginx to speed up our website. For example, we can use a Hong Kong VPS to configure NGINX to speed up our VPS website in the United States, which can improve the speed experience of website users. The above methods are only applicable to formal channels. This article refers to the content of jybb.me blog.

PS: If only telecommunications or a certain line is unstable, we can use DNSPOD analysis, and then carry out separate acceleration processing for different lines. The effect is quite obvious.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » In actual combat, Nginx is used to realize the anti proxy acceleration website to solve the problem of instability of overseas VPS lines


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge