Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Express返回404 for css.map_Node.js_Express - Fatal编程技术网

Node.js Express返回404 for css.map

Node.js Express返回404 for css.map,node.js,express,Node.js,Express,我正在使用nginx为一个express应用程序提供我的静态内容,这对于提供main.css很好,但是main.css是一个编译的sass文件,带有一个mapmain.map.css,它不是静态提供的,而是返回一个404GET/css/main.css.map 404 Nginx配置: server { listen 80; # Listens to all domains server_name _; # Static folder location in p

我正在使用nginx为一个express应用程序提供我的静态内容,这对于提供
main.css
很好,但是
main.css
是一个编译的sass文件,带有一个map
main.map.css
,它不是静态提供的,而是返回一个404
GET/css/main.css.map 404

Nginx配置:

server {
    listen 80;
    # Listens to all domains
    server_name _; 
    # Static folder location in project
    root project/public; 
    # Reverse proxy to express app listening on port 3001
    location / {
           proxy_pass http://localhost:3001;
           proxy_http_version 1.1;
           proxy_set_header X-Forwarded-Proto https;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_cache_bypass $http_upgrade;
    }
    # Caching 
}
我的问题是如何使node/express静态地为
.css.map
文件类型服务?或者有没有更好的方式通过express地图为sass服务

编辑

解决方案是将
css.map
类型添加到我的nginx缓存,这意味着缓存的任何文件类型都不会反向代理到express服务器,而是由nginx提供服务,并添加了相应的缓存控制

    # cache.appcache, HTML and Data
    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
            expires -1;
            add_header Access-Control-Allow-Origin *;
    }
    # Media: images, icons, video, audio, HTC
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
      expires 1M;
      access_log off;
              add_header Cache-Control "public";
    }
    # CSS and Javascript
    location ~* \.(?:css|css.map|js)$ { # Added map.css filetype
            expires 1y;
            access_log off;
    }
    # WebFonts
     location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
      expires 1M;
      access_log off;
    }

谢谢。

发布静态文件夹的nginx配置。我已经在问题中添加了nginx配置,您是否建议创建类似于
location~*.(?:css.map)
规则的内容,然后将其传递到静态文件夹?这样看起来您使用的是Express,而不是nginx。如果是这种情况,请更新问题并从你的app.jsI发布staticfiles配置,我假设是express static files被注释掉
//app.use(express.static(path.join(u dirname,'public'))
你是对的,我忽略的头缓存控件不会传递
.css
.js
文件来表示,而是传递
css.map
,我现在已经编辑了它。谢谢