优点:减少服务器请求延时

 

错误的配置, 由于location 匹配到js,css,png,并没有用上 location / {} 的 root配置.

server {
    listen       8089;
    server_name  localhost;

    sendfile on;
    #charset koi8-r;
    access_log  /var/log/nginx/log/static_access.log  main;

        location / {
                root /opt/mall/dist/;
                index index.html;
        }

        #图片缓存
        location ~ .*\.(js|css|jpg|png|gif)$ {
                expires 3d;
        }
}

 

正确的配置,  

server {
    listen       8089;
    server_name  localhost;

    sendfile on;
    #charset koi8-r;
    access_log  /var/log/nginx/log/static_access.log  main;

        root /opt/mall/dist;  #所有的location都使用该root

        location / {
                #root /opt/mall/dist/; 移除该行
                index index.html;
        }

        #图片缓存
        location ~ .*\.(js|css|jpg|png|gif)$ {
                expires 3d;
        }
}

 

 

 

 

 

 

posted on 2019-07-21 20:09  1161588342  阅读(737)  评论(0编辑  收藏  举报