ExpressJS /节点:404图像

我已经build立了一个基本的节点/快递服务器,公共静态JavaScript和CSS文件,但尝试提供图像时返回404错误。

最奇怪的部分是在本地运行时一切正常。 当在我的远程服务器(linode)上运行时,图像问题出现。

这真的让我挠脑袋…可能是什么问题?

这是服务器:

/** * Module dependencies. */ var express = require('express') , routes = require('./routes') var app = module.exports = express.createServer(); // Configuration app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })); app.use(express.static(__dirname + '/public')); app.use(app.router); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); }); // Globals app.set('view options', { sitename: 'Site Name', myname: 'My Name' }); // Routes app.get('/', routes.index); app.get('/*', routes.fourohfour); app.listen(3000); console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); 

如果在本地工作正常,也许这是一个大小写敏感的问题,你的文件有大写等?

我有这个问题,但它最终是因为我已经在后缀.JPG扩展名,并在HTML中调用.jpg。 Windows对文件types不区分大小写,CentOS是…

好吧,我通过将我的图像文件夹从“/ public / images”重命名为/ public / image来解决这个问题。 我不知道为什么命名会导致一个问题,但我很高兴这是所有需要的。

我有这个确切的问题。 上传到/static/uploads所有用户生成的图像都不是通过快递呈现的。 奇怪的是一切在static/imagesstatic/jsstatic/css正在好转。 我确定这不是一个权限问题,但仍然得到了404。最后,我configurationNGINX呈现我的所有静态文件(这可能更快),它的工作!

我仍然很想知道Express为什么不会渲染我的图像。

如果有人有这个问题,这是我的NGINX conf:

 server { # listen for connections on all hostname/IP and at TCP port 80 listen *:80; # name-based virtual hosting server_name staging.mysite.com; # error and access outout error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; location / { # redefine and add some request header lines which will be transferred to the proxied server proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; #set the location of the web root root /var/www/mysite.com; # set the address of the node proxied server. port should be the port you set in express proxy_pass http://127.0.0.1:9001; # forbid all proxy_redirect directives at this level proxy_redirect off; } # do a case insensitive regular expression match for any files ending in the list of extentions location ~* ^.+\.(html|htm|png|jpeg|jpg|gif|pdf|ico|css|js|txt|rtf|flv|swf)$ { # location of the web root for all static files root /var/www/mysite.com/static; # clear all access_log directives for the current level #access_log off; # set the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years #expires max; } }