2012-05-02 17 views
2

パブリック静的javascriptとcssファイルを提供する基本ノード/エクスプレスサーバーを設定しましたが、画像を提供しようとすると404エラーが返されます。ExpressJS/Node: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); 

答えて

2

それがローカルで正常に動作している場合、多分それはあなたのファイルは大文字などを持っていない、大文字と小文字の区別の問題ですか?

+0

No、capitilization。 –

+0

よろしく、私のイメージフォルダを "/ public/images"から "/ public/image"に改名してこの問題を回避しました。私はまだ命名が問題を引き起こす理由を知らないが、私はそれがすべて必要であることをうれしく思う。 私はこの質問に答える予定であり、期限に達すると終了します。 –

+0

私はそれが私のLinodeマシンと関係があると思う。 404はノードではなくnginxから来ています。返信TJに感謝します。私はもっ​​と研究する必要があります。 –

0

私は「/ public/images」から/ public/imageに画像フォルダの名前を変更して問題を回避しました。私はなぜこの命名が問題を引き起こすのか分からないが、私はそれがすべて必要だとうれしい。

0

私はこの正確な問題を抱えていました。 /static/uploadsにアップロードされたすべてのユーザー生成画像は、明示的に表示されませんでした。奇妙なことは、static/imagesstatic/jsstatic/cssのすべてがうまくいっています。私はそれが許可の問題ではなく、まだ404を取得していたことを確認しました。最後に、私はNGINXをレンダリングするように設定しましたすべて私の静的ファイルの(とにかく高速でしょう)

私はまだエクスプレスが私のイメージをレンダリングしていない理由を知りたいです。誰もがこの問題を持っている場合

ここに私の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; 
    } 
} 
1

私はこの問題を持っていたが、それは私が末尾.JPG拡張子でキャップを持っていたし、HTMLでの.jpgを呼んでいたことになってしまいました。 Windowsはファイルの種類では大文字と小文字を区別しませんが、CentOSは...