• nginx配置静态文件过期时间


    1. 编辑虚拟主机配置文件/usr/local/nginx/conf/vhosts/huangzhenping.conf

        说明:采用location方式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
        access_log off;
        expires 1d;
        }
        location ~ .(js|css)
        {
           access_log off;
           expires 1d;
        }

       wKioL1iuqD6CrZIPAAAYAw69t2k549.png

    2. 检查配置文件,重新加载,测试

        说明:google浏览器可以按F12,查看开发者工具或者用curl测试

        /usr/local/nginx/sbin/nginx -t

        /usr/local/nginx/sbin/nginx -s reload

     wKiom1iuqE7j4aIOAADopq91EZA697.png

        curl -x127.0.0.1:80 http://www.huanglearn.cn/static/image/smiley/default/mad.gif -I

     wKioL1iuqFiyDEfwAAA7br8VW5g187.png

    实际配置:

    server {
            listen       80;
            server_name  www.weifeng.cn;
    
    
            location /api/ {
                proxy_pass http://127.0.0.1:8088/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
    
            location / {
                try_files $uri /index.html;
                root   /home/*****ui/build;
                index  index.html index.htm;
            }
        
           location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
         {
            access_log off;
            expires 10d;
            root   /home******/ui/build;
         }
    
           location ~ .(js|css)
        {
           access_log off;
           expires 10d;
           root   /home******/ui/build;
        }
            
    
    }

    测试效果:

     curl -x127.0.0.1:80 http://www.weofemg.cn/static/js/main.5770cbc7.js -I
    HTTP/1.1 200 OK
    Server: nginx/1.14.0
    Date: Thu, 30 Aug 2018 06:55:51 GMT
    Content-Type: application/javascript
    Content-Length: 412411
    Last-Modified: Wed, 29 Aug 2018 12:28:50 GMT
    Connection: keep-alive
    ETag: "5b869182-64afb"
    Expires: Sun, 09 Sep 2018 06:55:51 GMT
    Cache-Control: max-age=864000
    Accept-Ranges: bytes
     
  • 相关阅读:
    Mapreduce实例-Top Key
    Mapreduce实例-分组排重(group by distinct)
    storm0.9.0.1升级安装
    mysql配置文件my.cnf详解
    MYSQL管理之主从同步管理
    一个经典实用的iptables shell脚本
    sed实例精解--例说sed完整版
    常用的主机监控Shell脚本
    Python(九)Tornado web 框架
    缓存、队列(Memcached、redis、RabbitMQ)
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/9560311.html
Copyright © 2020-2023  润新知