【问题标题】:elasticbeanstalk won't set virtual pathselasticbeanstalk 不会设置虚拟路径
【发布时间】:2018-06-14 16:06:36
【问题描述】:

我正在尝试新的 AWS Elastic Beanstalk 控制台 ui。我现在无法在 ui 上设置 虚拟路径

基本上,我将所有静态文件(包括 index.html)放在我的包内的文件夹 ui 中。

这是包结构:

/ui
/ui/favicon.ico
/ui/index.html
/ui/static
/ui/static/css/...
/ui/static/js/...
/ui/static/media/...
package.json
yarn.lock
app.js // this is the node api and it works

API 在访问我的 [http://public]/api/alive 时有效。我的意图是设置虚拟目录以从捆绑文件夹 ui 中提供静态文件。

当它不匹配任何东西时,节点 api 会发送 index.html。这有效:[http://public]/。我收到了index.html

然后浏览器请求静态文件/static/js/main[hash].js。这可行,但问题是我什至无法设置任何虚拟路径来玩。我需要将浏览器请求 /static 映射到 AWS 的 /ui/static

elasticbeanstalk 错误:

/static/:无效的选项规范(命名空间:'aws:elasticbeanstalk:container:python:staticfiles',OptionName:'/static/'):未知的配置设置。 static/:无效的选项规范(命名空间:'aws:elasticbeanstalk:container:python:staticfiles',OptionName:'static/'):未知的配置设置。 /assets:无效的选项规范(命名空间:'aws:elasticbeanstalk:container:python:staticfiles',OptionName:'/assets'):未知的配置设置。 静态:无效的选项规范(命名空间:'aws:elasticbeanstalk:container:python:staticfiles',选项名称:'static'):未知的配置设置。

无论我把斜线放在哪里,它都不起作用:

我指定的所有路径都存在于我部署的应用程序包中,除了 /static/assets 只是为了尝试不同的东西。

我不确定这是否是新 UI 上的错误。如果有人遇到同样的问题,请告诉我。

【问题讨论】:

  • 没关系。我将在单独的步骤中将 Web 静态文件部署到 S3。缺点是我必须对 API 进行跨域 API 调用。这可能是一个更好的结构。
  • 我遇到了与此处描述的完全相同的问题,如果有人有答案,我仍然对答案感兴趣。
  • 这可能会有所帮助:stackoverflow.com/questions/47646783/…
  • 我在那里找到了关于我的 Node.js EBS 的相同问题的答案 stackoverflow.com/a/47655177/1345244

标签: amazon-elastic-beanstalk


【解决方案1】:

只是为了详细说明 Nick 的答案 - 这里的 /html/images 将对应于您的环境期望接收文件的路径。

因此,如果您打开浏览器控制台的网络选项卡并看到如下内容: 404 GET http://your.app.com/static/admin/css/base.css

那么您可能希望路径为/static 而不是/html

statichtml 的值将对应于您的 eb 实例上静态文件的位置。

所以,如果你运行 eb ssh 然后 manage.py collectstatic 并得到这样的输出:

You have requested to collect static files at the destination
location as specified in your settings:

    /var/app/current/static

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

那么您可能希望值​​为/static/

【讨论】:

    【解决方案2】:

    我在尝试使用 Amazon Linux 2Python 3.7 Django 应用程序提供静态内容时发现了这个问题;但是,我认为不同平台的答案是相同的。

    阅读文档here我找到了这个链接:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-cfg-staticfiles.html

    表示.config 这样的示例文件

    示例.ebextensions/static-files.config

    option_settings:
      aws:elasticbeanstalk:environment:proxy:staticfiles:
        /html: statichtml  <-- path/to/your/static/dir/ (added by Nick)
        /images: staticimages
    

    所以,命名空间似乎从 aws:elasticbeanstalk:container:python:staticfiles 更改为 aws:elasticbeanstalk:environment:proxy:staticfiles。这似乎是一个更通用的反向代理,与平台无关,这是有道理的。干得好 AWS。

    当我尝试这个时,令人惊讶地文档是最新的并且有效。

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 1970-01-01
      • 2013-02-28
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      • 2020-07-15
      • 1970-01-01
      相关资源
      最近更新 更多