2016-11-14 46 views
-1

我具有長頸瓶/ nginx的應用程序,並要設置緩存2例如網址:蟒蛇瓶 - 如何在nginx的設置緩存

1. /category/apps-5.html 
2. /product/test-product-sell-34690064571.html 

我的實際nginx的配置是這樣的:

server { 
    listen 80 default_server; 
    listen [::]:80 default_server; 
    server_name _; 
    return 301 https://$host$request_uri; 
} 

server { 
    listen 443; 
    ssl on; 

    gzip on; 
    gzip_min_length 1000; 
    gzip_proxied expired no-cache no-store private auth; 
    gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml; 
    gzip_disable "MSIE [1-6]\."; 
    gzip_vary on; 

    server_name selfmarket.net www.selfmarket.net; 

    ssl_certificate /etc/letsencrypt/live/selfmarket.net/cert.pem;  # path to your cacert.pem 
    ssl_certificate_key /etc/letsencrypt/live/selfmarket.net/privkey.pem; # path to your privkey.pem 

    fastcgi_param HTTPS    on; 
    fastcgi_param HTTP_SCHEME   https; 

    # Serve static files and uploads 
    location ^~ /static/ { 
     root /opt/master/app/; 
    } 


    location/{ 
     proxy_pass 'http://127.0.0.1:8080/'; 
     proxy_redirect  off; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Forwarded-Host $server_name; 
    } 
} 

如何我能爲我的例子中的URL設置簡單的緩存(在3分鐘內到期)?是我第一次使用時的nginx ..即時通訊非常beginer,謝謝

回答

0

要做到這一點是緩存在後端的最好方法。 Flask具有簡單的緩存或者可以使用memcache。請參閱示例hereherehere

另外,如果你真的需要加快速度,你可以使用內置的內存緩存支持,Nginx已經(儘管這可能是太複雜)。有關更多詳細信息,請參閱此doc

如果您真的想要NGINX來做緩存,請查看proxy_cache模塊上的official docs。還有一個指南here