zoukankan      html  css  js  c++  java
  • Nginx 深入-动静分离, 静态资源css, js 前端请求404问题

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

    错误的配置, 由于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;
            }
    }

  • 相关阅读:
    2.25家庭记账本小软件
    2.10简单体温记录小软件总结
    4.26PHP
    4.25Android
    4.24css
    4.23css
    4.22电梯演讲
    4.21python
    4.20python
    4.19python
  • 原文地址:https://www.cnblogs.com/eason-d/p/11222496.html
Copyright © 2011-2022 走看看