Nodejs Elastic beanstalk 拒绝连接到上游/上游过早关闭
Nodejs Elastic benastalk refused to connect to upsteam/ upsteam prematurely closed
当我在 elastic beanstalk 中 运行 我的应用程序时出现以下错误:[error] 3636#0: *295 upstream prematurely closed connection while reading response header from upstream
和 [error] 3636#0: *295 connect() failed (111: Connection refused) while connecting to upstream
这很奇怪,因为如果我独立地访问这些路由,它就可以正常工作。只有在从我的 vuex 操作中触发这些路由时才会出现错误。
以下是来自AWS elastic beanstalk的日志。
下面是它命中我的FFmpeg路由时的网络选项卡:
以下是从 vuex 触发的生成视频操作。
async [GENERATE_VIDEO]({state, rootState, dispatch, commit}){
const username = rootState.user.currentUser.username;
const s3Id = rootState.templates.currentVideo.stock_s3_id;
const type = rootState.dataClay.fileFormat || state.type;
const vid = new Whammy.fromImageArray(state.captures, 30);
vid.lastModifiedDate = new Date();
vid.name = "canvasVideo.webm";
const data = new FormData();
const id = `${username}_${new Date().getTime()}`;
data.append("id", id);
data.append("upload", vid);
const projectId = await dispatch(INSERT_PROJECT);
await dispatch(UPLOAD_TEMP_FILE, data);
const key = await dispatch(CONVERT_FILE_TYPE, { id, username, type, projectId});
const role = rootState.user.currentUser.role;
state.file = `/api/files/${key}`;
let message;
if(role!='banner'){
message =`<p>Your video is ready.</p> <a href="${state.file}" download class="btn btn-primary btn-block">Download</a>`;
} else {
message = `<p>Your video is ready. You may download your file from your banner account</p>`;
const resolution = rootState.dataClay.matrix[0];
await dispatch(EXPORT_TO_BANNER, { s3Id, fileUrl: key, extension: `.${type}`, resolution});
}
这里是在操作中调用的 api 路由。
async [UPLOAD_TEMP_FILE]({ commit }, data) {
try {
const response = await axios.post("/api/canvas-editor/upload-temp", data);
return response.data;
} catch (error) {
console.log(error);
}
},
async [CONVERT_FILE_TYPE]({commit}, data) {
try{
const response = await axios.post("/api/canvas-editor/ffmpeg", data);
return response.data;
} catch(error){
console.log(error);
}
}
}
正如我所说,我的所有路由都有效,应用程序在本地主机上按预期运行,但是当上传到 aws 时,我收到意外错误。
经过一番挖掘,我发现我没有设置 ffmpeg 路径。
完成后效果很好。
const ffmpeg = require('fluent-ffmpeg');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
ffmpeg.setFfmpegPath(ffmpegPath);
module.exports = ffmpeg;
当我在 elastic beanstalk 中 运行 我的应用程序时出现以下错误:[error] 3636#0: *295 upstream prematurely closed connection while reading response header from upstream
和 [error] 3636#0: *295 connect() failed (111: Connection refused) while connecting to upstream
这很奇怪,因为如果我独立地访问这些路由,它就可以正常工作。只有在从我的 vuex 操作中触发这些路由时才会出现错误。
以下是来自AWS elastic beanstalk的日志。
下面是它命中我的FFmpeg路由时的网络选项卡:
以下是从 vuex 触发的生成视频操作。
async [GENERATE_VIDEO]({state, rootState, dispatch, commit}){
const username = rootState.user.currentUser.username;
const s3Id = rootState.templates.currentVideo.stock_s3_id;
const type = rootState.dataClay.fileFormat || state.type;
const vid = new Whammy.fromImageArray(state.captures, 30);
vid.lastModifiedDate = new Date();
vid.name = "canvasVideo.webm";
const data = new FormData();
const id = `${username}_${new Date().getTime()}`;
data.append("id", id);
data.append("upload", vid);
const projectId = await dispatch(INSERT_PROJECT);
await dispatch(UPLOAD_TEMP_FILE, data);
const key = await dispatch(CONVERT_FILE_TYPE, { id, username, type, projectId});
const role = rootState.user.currentUser.role;
state.file = `/api/files/${key}`;
let message;
if(role!='banner'){
message =`<p>Your video is ready.</p> <a href="${state.file}" download class="btn btn-primary btn-block">Download</a>`;
} else {
message = `<p>Your video is ready. You may download your file from your banner account</p>`;
const resolution = rootState.dataClay.matrix[0];
await dispatch(EXPORT_TO_BANNER, { s3Id, fileUrl: key, extension: `.${type}`, resolution});
}
这里是在操作中调用的 api 路由。
async [UPLOAD_TEMP_FILE]({ commit }, data) {
try {
const response = await axios.post("/api/canvas-editor/upload-temp", data);
return response.data;
} catch (error) {
console.log(error);
}
},
async [CONVERT_FILE_TYPE]({commit}, data) {
try{
const response = await axios.post("/api/canvas-editor/ffmpeg", data);
return response.data;
} catch(error){
console.log(error);
}
}
}
正如我所说,我的所有路由都有效,应用程序在本地主机上按预期运行,但是当上传到 aws 时,我收到意外错误。
经过一番挖掘,我发现我没有设置 ffmpeg 路径。 完成后效果很好。
const ffmpeg = require('fluent-ffmpeg');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
ffmpeg.setFfmpegPath(ffmpegPath);
module.exports = ffmpeg;