Last update at :2023-12-26,Edit by888u
I opened a good friend’s blog, and the speed was pretty good. I thought I was using a Mainland China vps host, so I asked about the foreign host I was using, and I used the 256M package of Hostus’s Hong Kong vps host to jump. In view of the fact that the prices of vps hosts in mainland China are not cheap, and the Hong Kong vps hosts have also released some bargains after the establishment of the SL datacenter, the Chinese people are also constantly adjusting prices, so it is a good idea to use Hong Kong vps hosts to jump choose. Now this article uses NGINX to achieve the purpose of reverse-generation acceleration of the website. The operation method is as follows:
First, install the NGINX environment
You can install NGINX by directly compiling the source, or you can directly use Jun Ge’s LNMP one-click package to install the system environment with the NGINX environment, or you can directly use the AMH4.2 free version to download the relevant plug-ins. There are many methods, just find the one that suits you. I will later release how to use the AMH free version to build it.
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
Pay attention to the red part and find yours!
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 cache area name, 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;
#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
301 status cached 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.
Third, restart NGINX to take effect
/etc/init.d/nginx restart
In this way, 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 method is very simple and very suitable for users who love to mess around. Pay attention to changing the domain name to your own! If you want to try it, you must try it. If you don't experience it, it's just like talking on paper! I don’t know who released these methods first, but I would like to pay tribute to the elders!
Recommended site searches: Telecom hosting, Alibaba Cloud registration, US attack-proof server, IP online query, how to query IP address, registration-free CDN, Hong Kong server rental, private server rental, overseas server rental price, latest qq agent ip,
发表评论