【问题标题】:AWS Elastic Beanstalk wont load static files from public folder for nodejs appAWS Elastic Beanstalk 不会从 nodejs 应用程序的公共文件夹中加载静态文件
【发布时间】:2019-10-09 21:34:21
【问题描述】:

我已经使用 aws eb deploy 部署了 nodejs 应用程序,client.js 没有加载到 index.hbs 文件中并返回 404 错误(加载资源失败:服务器响应状态为 404(未找到))

我已经尝试了互联网上的所有步骤,为此浪费了两天时间。

有人可以帮我吗?我在这里做错了什么?

我已经在这个 stackover 流程​​页面Elastic Beanstalk Static Folder 403 Error 中尝试了解决方案,但没有运气

staticfiles.config(NodejsPlayGround.elasticbeanstalk\staticfiles.config)文件

option_settings:

aws:elasticbeanstalk:container:nodejs:staticfiles:
/public: public

index.hbs(NodejsPlayGround\views\index.hbs)文件

<!DOCTYPE html>
<html>
<head>
<title>NodeSeverTest</title>
<script src="js/client.js"></script>
</head>
<body>
<h1>Hello</h1>
</body>
</html>

server.js(NodejsPlayGround\server.js)文件

'use strict';
const express = require('express');
const path = require('path');

const app = express();
const port = process.env.PORT || 3000;

const views_path = path.join(__dirname, 'views');
const static_path = path.join(__dirname, 'public')

app.set('view engine', 'hbs');
app.set('views', views_path);

app.get('', (req, res) => {
res.render('index', {
title: 'Weather App',
name: 'ArunKumar Arjunan'
}
);
});
app.listen(port, () => {
console.log('server started on port ' + port);
});

client.js(NodejsPlayGround\public\js\client.js)文件:

console.log('client side java script file is loaded');

client.js 文件需要加载到 index.hbs 文件中

【问题讨论】:

    标签: node.js amazon-web-services amazon-elastic-beanstalk ebcli


    【解决方案1】:

    我发现与 AWS 文档相反,文件夹路径还需要一个前导斜杠 — 即您将 /public 映射到 /public(不仅仅是 public),或者将 /static 映射到 /static(不仅仅是static)。

    我通过检查我的 EB 实例上的 nginx 错误日志和 conf 文件发现了这一点,两者都表明它正在/var/app/currentstatic而不是/var/app/current/static中寻找我的静态文件。

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 2018-10-16
      • 1970-01-01
      • 2018-03-11
      • 2019-04-27
      • 2020-09-28
      • 2020-11-15
      • 2015-04-06
      • 2019-02-01
      相关资源
      最近更新 更多