Image ExpressJS/Node:404图像

Image ExpressJS/Node:404图像,image,node.js,express,http-status-code-404,linode,Image,Node.js,Express,Http Status Code 404,Linode,我已经建立了一个基本的node/express服务器,它可以很好地服务于公共静态javascript和css文件,但在尝试服务于图像时返回404错误 最奇怪的是,当在本地运行时,一切都很好。在我的远程服务器(linode)上运行时,映像问题会出现 这真让我抓狂。。。有什么问题吗 这是服务器: /** * Module dependencies. */ var express = require('express') , routes = require('./routes') var

我已经建立了一个基本的node/express服务器,它可以很好地服务于公共静态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);

如果它在本地工作正常,可能是区分大小写的问题,您的文件是否有大写字母等?

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

我有这个确切的问题。express未呈现上载到
/static/uploads
的所有用户生成的图像。奇怪的是,
static/images
static/js
static/css
中的一切都很好。我确保这不是权限问题,但仍然得到了404。最后,我配置了NGINX来呈现我所有的静态文件(不管怎样,这可能会更快),它工作了

我仍然很想知道为什么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;
    }
}

我有这个问题,但结果是我在后面的.JPG扩展中使用了caps,并在html中调用了.JPG。Windows对文件类型不区分大小写,CentOS是…

好的,我通过将我的图像文件夹从“/public/images”重命名为“/public/image”来解决这个问题。我仍然不知道为什么命名会引起问题,但我很高兴这就是所需要的。我将回答这个问题,并在到达时间限制时关闭它。我认为这与我的Linode机器有关。404来自nginx,而不是node。谢谢你的回复TJ;我还有更多的研究要做。