Last update at :2024-04-25,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 losses. 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.
Some people may ask, why not just put the website in Asia or mainland China, but also create a counter-generation, which is so troublesome. That’s because VPS in Asia is relatively expensive. If you want to go against the current generation, just use a low-end VPS.
First, install the NGINX environment
Here we can use the method of directly compiling the source to install NGINX, or we can directly use Jun Ge's LNMP one-click package to install the system environment with the NGINX environment.
Second, add the 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 -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 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, the default is used without modification.
D - Configure example.com.conf
listen 80;
server_name example.com www.example.com;
#Bound domain name
index index.php;
#DefaultHomepage
access_log off;
#off Turn off logs
location / {
proxy_cache_key "$scheme://$host$request_uri";
#Cache key rules, 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 for 3 hours
Cache 301 status for 3 days
Other status caching (such as 502 404) for 10 seconds
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Pass the visitor 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 backend IP, you can add a port
#proxy_cache_use_stale invalid_header error timeout http_502;
#Enable expiration 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 low-configuration NGINX to accelerate our VPS website with website data in the United States can improve the speed and experience of website users. The above methods can only be used through formal channels.
Recommended site search: free permanent high-performance server, permanent free Linux server, application for free space and domain name, Beijing host rental, Ministry of Industry and Information Technology filing system website icp filing, game high-defense server rental domain name registration price, private server Server rental, Tencent cloud server,
发表评论