在 Elastic Beanstalk 上扩展 Nginx - Node JS

Posted

技术标签:

【中文标题】在 Elastic Beanstalk 上扩展 Nginx - Node JS【英文标题】:Extend Nginx on Elastic Beanstack - NodeJS 【发布时间】:2020-10-23 12:58:29 【问题描述】:

寻找一种在弹性 beanstalk 环境中扩展 nginx 配置的方法。我只需要一个像下面这样的简单代理,这样单页应用程序就可以通过 AJAX 访问 API。我们无法将 CORS 用于我们的用例。

我按照亚马逊上的文档进行操作,但无法使其正常工作。我当前的设置具有以下文件夹结构:

node_app ..ebextensions .... nginx ...... conf.d ........ 01_app_proxy.conf

location /api/v1 
    proxy_pass          https://my-api.com;
    proxy_http_version  1.1;
    proxy_set_header    Connection          $connection_upgrade;
    proxy_set_header    Upgrade             $http_upgrade;
    proxy_set_header    X-Real-IP           $host;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;

实例 - Amazon Linux 第 2 版 (Karoo)

【问题讨论】:

【参考方案1】:

它不起作用的一个可能原因是因为以下设置

 .ebextensions .... nginx ...... conf.d ........ 01_app_proxy.conf

适用于 Amazon Linux 1。但是,您声明您使用的是 Amazon Linux 2

对于 AL2,设置在 .platform 文件夹中,而不是在 .ebextensions 中,如图所示 here。

另请注意,AL1 和 AL2 之间存在许多差异。如果您将应用从 AL1 移植到 AL2 环境,您可能需要更改其他内容:

Migrating your Elastic Beanstalk Linux application to Amazon Linux 2

希望这会有所帮助。

【讨论】:

谢谢 Marcin - 你说得对。我还必须更改放置 conf 文件的位置。要扩展它,它必须进入 elasticbeanstalk 文件夹 .platform/nginx/conf.d/elasticbeanstalk/01_app_proxy.conf。

以上是关于在 Elastic Beanstalk 上扩展 Nginx - Node JS的主要内容,如果未能解决你的问题,请参考以下文章

如何使用配置文件 (.ebextensions) 在 AWS Elastic Beanstalk 上安装 PHP IMAP 扩展?

Elastic Beanstalk NetworkOut 自动扩展

在 Elastic Beanstalk 中扩展实例会破坏 python 烧瓶应用程序的动态图像链接

在 Elastic Beanstalk 上公开 POST 端点

在AWS Elastic Beanstalk上启用LDAP

在 Elastic Beanstalk 上使用 catalina.out 缓解存储问题