How to enable VPS in foreign countries using Nginx to implement reverse-generation acceleration websites

Source: Internet
Author: User
Tags memory usage mkdir disk usage vps

1. Install the NGINX environment

Here we can use the method of directly compiling the source to install NGINX, or directly use the LNMP one-key package of June to install the system environment with the NGINX environment.

2. Add the site configuration file

A-you can use the LNMP environment package vhost to add sites, or manually add virtual host site configuration in the nginx environment.
The code is as follows: Copy code
Vi/usr/local/nginx/conf/vhost/example.com. conf
The red example.com part is our site domain name.
B-set directory permissions
The code is as follows: Copy code
Mkdir/home/cache/path-p
Mkdir/home/cache/temp
Chmod 777-R/home/cache
Set the cache directory permission storage path.
C-configure the nginx conf file
The code is as follows: Copy code
Proxy_connect_timeout 5;
Proxy_read_timeout 60;
Proxy_send_timeout 5;
Proxy_buffer_size 16 k;
Proxy_buffers 4 64 k;
Proxy_busy_buffers_size 128 k;
Proxy_temp_file_write_size 128 k;
Proxy_temp_path/home/cache/temp;
# Temporary file directory
Proxy_cache_path/home/cache/path levels = keys_zone = cache_one: 5 m inactive = 7d max_size = 1g;
#5 MB indicates memory usage, 1 GB indicates the maximum disk usage, and cache_one indicates the cache zone name. Modify the value if necessary.
You need to configure the cache corresponding to the path in B. Do not modify it directly by default.
D-configure example.com. conf
The code is as follows: Copy code
Listen 80;
Server_name example.com www.example.com;
# Bound domain name
Index. php;
# Default homepage
Access_log off;
# Off disable logs
Location /{
Proxy_cache_key "$ scheme: // $ host $ request_uri ";
# Cache key rule, used to automatically clear the cache.
Proxy_cache cache_one;
# Cache zone name, which is the same as the previously defined
Proxy_cache_valid 200 304 3 h;
Proxy_cache_valid 301 3d;
Proxy_cache_valid any 10 s;
#200 304 status cache for 3 hours
301 status cache for 3 days
Other status caches (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 address to the backend
Proxy_set_header Referer http://example.com;
# Force Referer definition, which will be used for program verification and judgment
Proxy_set_header Host $ host;
# Define the host header
Proxy_pass http: // 1.2.3.4;
# Specify the backend ip address and add a port
# Proxy_cache_use_stale invalid_header error timeout http_502;
# Use it with caution when an error, timeout, or 502 occurs on the backend.
}
}

When the domain name is resolved, you can point to the front-end IP address. For more information about the annotations, see if you need to modify the annotations.

3. Restart NGINX to take effect

The code is as follows: Copy code
/Etc/init. d/nginx restart
Through the above four steps, we can use nginx to accelerate our website. For example, we can use a Hong Kong VPS to Configure NGINX and provide us with VPS website acceleration for website data in the United States, it can improve the speed and experience of website users. The above method is only used in regular channels. For details, refer to the jybb. me blog.
PS: If it is just China Telecom or a certain line is unstable, we can use DNSPOD resolution, and then separate acceleration processing for different lines. The effect is quite obvious.
Related Article

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.