1

我有一个 VPS(ubuntu 14.04)和一个带有multer的 nodejs 应用程序,用于处理程序文件上传,当我通过 node ex.“node my-server.js”启动服务器时它可以工作

但如果我通过upstart ex. "sudo start node-app" node-app 是一个 ubuntu upstart conf 文件,则不是这里是代码

multer 我在这里使用 express 是代码。我的服务器.js

app.use(multer({
  dest: './public/images/',
  rename: function(fieldname, filename) {
    return filename;
  }
}));

我的新贵文件:/etc/init/node-app.conf

description "node.js server"
author      "Name"

start on (local-filesystems and net-device-up IFACE=wlan0)

stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    export HOME="/home/username/www/site-server/"
    exec node $HOME/bin/www 13002 >> /var/log/node.log 2>&1
end script

在我的 node.log 上我有这个。

{ [Error: Command failed: identify.im6: unable to open image `/home/username/www/my-node-app/public/images/hqdefault.jpg': No such file or directory @ error/blob.c/OpenBlob/2638.
] timedOut: false, killed: false, code: 1, signal: null }

知道为什么不通过暴发户工作吗?

4

2 回答 2

0

It needs to be able to write uploaded files to disk, so it probably doesn't have permission to write to the destination directory.

Ensure that upstart runs it from user account that has access to upload directory you've configured in multer.

于 2015-04-18T11:00:59.083 回答
0

正如@porneL 所说,ubuntu 用户需要在磁盘上写入的权限,所以我更改了我的新贵文件。

由此。

export HOME="/home/username/www/site-server/"
exec node $HOME/bin/www 13002 >> /var/log/node.log 2>&1

对此

export HOME="/home/username/www/"
cd $HOME/site-server/
exec node bin/www >> /var/log/node.log 2>&1

是我找到答案的地方。

于 2015-04-18T16:09:07.260 回答