Nginx cache and program static and dynamic separation settings

Source: Internet
Author: User

First, configure the Nginx cache.

Reference: Http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path syntax proxy_cache_path path  [Levels=levels] keys_zone=name:size [inactive=time] [max_size=size] [loader_files=number]  [loader_sleep=time] [loader_threshold=time]; Configuration Format:proxy_cache_path /data/nginx/cache  levels=1:2 keys_zone=one:10m; #定义/data/nginx/cache for the cache directory;levels=1:2  has a Level 2 subdirectory, up to 3 levels of subdirectories, separated by a colon to define 3 numbers, Each number represents its directory name;keys_zone=one:10m  how much space is used to save the key value; 1.nginx Cache settings: Vim /data/nginx/conf/nginx.confuser nginx  nginx;worker_processes auto;pid  /data/nginx/logs/nginx.pid;worker_rlimit_nofile  65535;events {    use epoll;    worker_connections  65535;    multi_accept on;} http {    include       mime.types;     default_type  application/octet-stream;    charset   utf-8;    log_format  main   ' $remote _addr -   $remote _user [$time _local]  "$request"   $http _host '                         ' $status   $upstream _status  $body _bytes_sent  "$http _referer"   "                        ' $http _user_agent '   "$upstream _addr"   "$http _x_forwarded_for"   ';     #access_log   logs /access.log  main;    sendfile       on;     tcp_nopush     on;    keepalive_timeout   60;    server_tokens  off;    limit_rate_after  3m;   &nBsp;limit_rate 512k;     tcp_nodelay on;    client_ header_buffer_size 256k;    large_client_header_buffers 4 256k;      #Define  nginx proxy module        proxy_ http_version 1.1;        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;        &Nbsp;proxy_headers_hash_max_size 51200;        proxy_headers_hash _bucket_size 6400;         #需要在http字段, setting nginx cache         proxy_temp_path /data/nginx/proxy_temp_path;         proxy_cache_path /data/nginx/proxy_cache_path levels=1:2 keys_ Zone=cache_one:50m inactive=20m max_size=30g;# define gzip compression module     gzip on;    gzip_vary on;    gzip_ min_length  1k;    gzip_buffers     4 16k;     gzip_http_version 1.0;    gzip_comp_level 2;     gzip_types       text/plain application/x-javascript text/ css application/xml;    # define realserver pool    upstream   tomcat_server {        ip_hash;         server 192.168.1.10:5678        max_fails=0   weight=2;        server 192.168.1.20:7890         max_fails=0  weight=1;   }     server {        listen        80;        server_name  beyond.com www.beyond.com ;

The Nginx cache is successful and can be viewed in the cache directory:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/91/wKioL1WhQmLwXkmYAAKNfV79NnY832.jpg "title=" 1.png " alt= "Wkiol1whqmlwxkmyaaknfv79nny832.jpg"/>

Second, static data access local, static data to local nginx processing. Dynamic data is delivered to the backend agent's Tomcat server for processing.

Location ~ .*\. (png|gif|jpg|jpeg|bmp|swf) $ {        root /data/node1/ webapps/root;   #反向代理图片服务器, where the static data is handed over to local processing.         expires 1d;                       #缓存一天          proxy_cache one;                  #引用定义的缓存模块名称         proxy_ cache_valid 200 1h;        #请求返回值为200的则缓存1小时          proxy_cache_valid 302 10m;      # The request returns a value of 301 302 cache for 10 minutes         proxy_cache_valid any 10s;        #其他任何返回值缓存10秒     &NBsp;   add_header x-via  $server _addr;   #定义这个header名为X-via  through variables $server_ Addr clearly describes which server to respond to  server_addr        add_header  x-cache-status  $upstream _cache_status, #明确说明是否命中   $upstream _cache_status for upstream modules          }  Dynamic Data to the back-end agent Tomcat, to achieve static and dynamic separation. Of course, as a CDN, that said, you can separate the static data into another domain name.         location ~ \. (do|jsp|php) $ {                 proxy_pass  http://tomcat_server;                 proxy_set_header Host  $host;                 proxy_set_header X-Real-IP         $remote _addr;                proxy_set_header x-forwarded-for  $proxy _add_x _forwarded_for;        }

This article from the "Years in the passing, shining still in" blog, please be sure to keep this source http://taokey.blog.51cto.com/4633273/1673314

Nginx cache and program static and dynamic separation settings

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.