NGINX 缓存服务
- upstream imooc {
- server 116.62.103.228:8001;
- server 116.62.103.228:8002;
- server 116.62.103.228:8003;
- }
-
- proxy_cache_path /opt/app/cache(存放缓存文件目录) levels=1:2(缓存目录分级) keys_zone=imooc_cache(开辟空间的名字):10m(空间的大小) max_size=10g(最大的大小) inactive=60m(设置多长时间没访问到就清理掉) use_temp_path=off;
-
- server {
- listen 80;
- server_name localhost jeson.t.imooc.io;
-
- #charset koi8-r;
- access_log /var/log/nginx/test_proxy.access.log main;
-
- if ($requst_url ~ ^/(url3|login|register|password\/reset)) {
- set $cookie_nocache 1;
- }
-
- location / {
- proxy_cache off;
- proxy_pass http://imooc;
- proxy_cache_valid 200 304 12h(200 304返回的头信息 12小时过期);
- proxy_cache_valid any 10m(除200和304 10分钟过期);
- proxy_cache_key $host$uri$is_args$args(缓存的key);
- add_header Nginx-Cache "$upstream_cache_status"(增加一个头信息);
-
- proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504(如果服务器返回的是500 502 503 504就跳过这一台访问下一台服务器);
- proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;(不缓存)
- proxy_no_cache $http_pragma $http_authorization;(不缓存)
- include proxy_params;
- }