Nginx File Cache service configuration record (Proxy_cache)

Source: Internet
Author: User

Request a cache server for a file based on the business unit requirements. The following records deploy the Nginx cache service process on a single machine:

Nginx Cache Configuration (The parameters of the cache configuration are not explained too much here, as explained in the previous document, only simple records are done here)

[[email protected] ~]# cat/data/nginx/conf/nginx.conf|grep-v "^$" |grep-v "#" user www;worker_processes 8;  Events {worker_connections 65535;}    HTTP {include mime.types;    Default_type Application/octet-stream;     CharSet Utf-8; Log_format Main ' $http _x_forwarded_for $remote _addr $remote _user [$time _local] "$request" "$statu    s $body _bytes_sent "$http _referer" "$http _user_agent" "$http _cookie" $host $request _time ';    Sendfile on;    Tcp_nopush on;    Tcp_nodelay on;     Keepalive_timeout 65;    Proxy_temp_path/data/nginx/proxy_temp;         Proxy_cache_path/data/nginx/proxy_cache levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=30g;    Client_header_timeout 600s;      Client_body_timeout 600s;                 Client_max_body_size 50m;                 Client_body_buffer_size 256k;    gzip on;    Gzip_min_length 1k;    Gzip_buffers 4 16k;    Gzip_http_version 1.1; Gzip_comp_level 9;    Gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;      Gzip_vary on; Include vhosts/*.conf;} Note: The cache directory/proxy_cache and/proxy_temp must be under the same partition, and the permissions must be consistent with the Nginx program permissions (that is, to have write permission, otherwise it cannot produce cache files)! [[email protected] ~]# mkdir/data/nginx/proxy_cache[[email protected] ~]# mkdir/data/nginx/proxy_temp[[ Email protected] ~]# chown-r www.www/data/nginx/proxy_cache[[email protected] ~]# chown-r www.www/data/     Nginx/proxy_temp [[email protected] ~]# cat/data/nginx/conf/vhosts/img.confserver {Listen 80;     server_name img.wang.com;     Access_log/data/nginx/logs/img-access.log main;     Error_log/data/nginx/logs/img-error.log;         Location/{index index.html index.htm;         root/data/img/;         Proxy_cache Cache_one;         Proxy_cache_valid 304 12h;         Proxy_cache_valid 301 302 1m;         Proxy_cache_valid any 1m; Proxy_cache_key $host $uri$is_args$args;      } location ~/purge (/.*) {allow all;      Proxy_cache_purge Cache_one $host $1$is_args$args;    Error_page 405 =200/purge$1; }}[[email protected] ~]#/data/nginx/sbin/nginx-tnginx:the configuration file/data/nginx/conf/nginx.conf Syntax is oknginx:configuration file/data/nginx/conf/nginx.conf test is successful[[email protected] ~]#/data/ Nginx/sbin/nginx [[email protected] ~]# ll-d/data/imgdrwxr-xr-x 3 www www 4096 10:06/data/img[[email p Rotected] ~]# ll/data/imgtotal 8drwxr-xr-x 2 www www 4096-image-rwxr-xr-x 1 www www-15:44 index. Html[[email protected] ~]# ll/data/img/image/total 20-rwxr-xr-x 1 www www 19270, 19:50 wang.png[[email pr Otected] ~]# cat/data/img/index.html CACHE server!!!!!

Access

viewing cache files

[[email protected] ~]# ll/data/nginx/proxy_cache/total 12drwx------3 www www 4096 10:20 0drwx------3 www www 409 6 10:14 edrwx------3 www www 4096 10:15 f[[email protected] ~]# ll/data/nginx/proxy_cache/etotal 4drwx---- --2 www www 4096 10:29 e3 the            structure of the above cache file is determined by the levels=1:2, that is, the first level directory is a letter name, the second level directory is two letters

Clean up the cache

Nginx File Cache service configuration record (Proxy_cache)

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.