Nginx reverse proxy cache to implement CDN

Xiao Cen has a few VPSs in his hand, thinking about making a mirror site for the blog, it is more troublesome to think about it, so he configures the reverse proxy of the nginx of the idle VPS, and then performs load balancing through DNSPOD. The configuration configuration is as follows (Note: This configuration is only effective for http, please ask Du Niang again for the configuration of https.)

1. Create two new directories and place cache files:

  mkdir /home/cache/path -p
  mkdir /home/cache/temp -p
  2. Modify /usr/local/nginx/conf/nginx.conf and add the following code, mainly for cache related settings, please place it in http{ # #Here} can be added above or below log_format:

  client_body_buffer_size 512k;
  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;
  proxy_temp_path /home/cache/ temp; home proxy/200 inactive=7d max_size=50g;
  #200m is memory usage, 7d is 7 days without access to delete, 5g is cache occupies hard disk space, estimate the space, NGINX will cache all pages
  3. Modify the virtual host configuration file, you can save it as xxx.conf is placed under vhost
  
server
  {
  listen 80;

server_name www.crazycen.com; #host name

  location / {
  proxy_cache cache_one;
  proxy_cache_valid 200 304 3d ; #Normal state cache time 3 days
  proxy_cache_key $host$uri$is_args$args;
  proxy_pass  http://www.crazycen  ; #Fill in the website you want to proxy here, because it is only for acceleration, Just the same as the host name
  proxy_redirect off;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  expires 10d;
#default 10 days cache access_log /home/wwwlogs/vpsmm.log access; #Log file
  }
  4 . Test configuration
/usr/local/nginx/sbin/nginx -t if prompted: "the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx. "conf test is successful" means normal. If there is an error, please troubleshoot according to the error prompt.

5. Cache test, you can modify the local host file, point to the proxy server ip, test whether the website cache is normal, click the website, df -sh command, check the size of the /home/cache directory, you can test whether the cache is successful. This script is fully cached on the front end. After the back end is dynamically updated, the front end will not be automatically modified. You can manually clean up files in the cache directory.
6. After the test is successful, you can go to DNSPOD to add the A record of the current agent.


Guess you like

Origin blog.51cto.com/15015155/2554672