单页面部署去Html缓存 nginx/openresty

单页面nginx/openresty部署,去除Html缓存问题(设置客户端不缓存):

server {
    listen       80;
    server_name xxxx.com;
    # etag off; # 负载均衡情况下关闭
    underscores_in_headers on;
    location / {
       if ($request_filename ~ .*\.(htm|html)$) {
            expires -1s;
            add_header Cache-Control no-cache;
        }

        root  /home/xxx/dist;
        try_files $uri $uri/ = /index.html;
        index index.html;
    }

    location ^~/api/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;

        proxy_set_header Host $host;
        # 后台API对接地址
        proxy_pass http://127.0.0.1:0000/api/;
    }
}

展示评论