Last update at :2024-06-26,Edit by888u
If we have users who use overseas VPS to build Chinese websites, they will definitely experience line instability and even a large number of packet loss problems. This is especially true for telecom broadband users from night to midnight. No matter what the reason is, we must consider the solution ourselves, either choosing an Asian line or a mainland China server, or we can use anti-generation acceleration methods to speed up the website.
In this article, Snail tries to use NGINX to achieve the purpose of reverse generation acceleration of the website. I have read many similar articles before, but have not put them into practice, so I just have some time this afternoon to do it for real. The same will be recorded in the form of pictures and texts so that friends in need can view and use it.
First, install the NGINX environment
Here we can use the direct compilation source method to install NGINX, or we can directly use Jun Ge's LNMP one-click package to install the system environment with the NGINX environment (LNMP one-click installation package basic tutorial directory).
Second, add site configuration file
A – Here you can use the LNMP environment package vhost to add a site, or you can manually add a virtual host site configuration in the nginx environment.
vi /usr/local/nginx/conf/vhost/example.com.conf
The red example.com part is our site domain name.
B – Set directory permissions
mkdir /home/cache/path -pmkdir /home/cache/tempchmod 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/c ache/path levels=1:2 keys_zone =cache_one:5m inactive=7d max_size=1g;#5m is the memory usage, 1g is the maximum hard disk usage, cache_one is the name of the cache area, modify it if necessary.
The cache needs to be configured corresponding to the path in B. Generally, use the default and do not modify it.
D – Configure example.com.conf
listen 80;server_name example.com www.example.com;#Binded domain name index index.php;#Default homepage access_log off;#off Close the log location / {proxy_cache_key \\”$scheme://$host $request_uri\\”;#Cache key rule, used to automatically clear the cache. proxy_cache cache_one;#Cache area name, the same as previously defined proxy_cache_valid 200 304 3h;proxy_cache_valid 301 3d;proxy_cache_valid any 10s;#200 304 status cache 3 hours 301 status cache 3 days other status cache (such as 502 404) 10 seconds proxy_set_header X -Real-IP $remote_addr;proxy_set_header Host header proxy_pass http://1.2.3.4;#Specify the backend ip, you can add a port#proxy_cache_use_stale invalid_header error timeout http_502;#Enable expired cache when an error, timeout, or 502 status occurs in the backend, use with caution. }}
When resolving domain names, just point to the front-end IP. We can study 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 4 steps, we can use nginx to accelerate our website. For example, using a Hong Kong VPS to configure NGINX and accelerating our VPS website with website data in the United States can improve the speed of website user access. The above methods can only be used in formal channels. This article refers to the jybb.me blog content.
PS: If it is just telecommunications or a certain line is unstable, we can use DNSPOD analysis and then perform separate acceleration processing for different lines. The effect is quite obvious.
Recommended site search: Hong Kong server, agency service IP, website server hardware configuration, website server rental, Guangdong server rental, virtual host rental, cpanel space, free virtual host application, foreign server rental price, domain name registration website,
p>
发表评论