【问题标题】:Why I get ElasticBeanstalk::ExternalInvocationError?为什么我得到 ElasticBeanstalk::ExternalInvocationError?
【发布时间】:2018-05-27 00:02:27
【问题描述】:

我的应用程序是基于 RubyOnRails 构建的,它使用乘客部署为弹性 beanstalk 应用程序,我正在尝试将标头添加到 nginx 服务器并重新启动它,这是我的配置文件,来自 aws elastic beanstalk 中 .ebextensions 文件夹的脚本:

packages: 
    yum:
        nginx: [] 

files:
    "/etc/nginx/conf.d/webapp.conf" :
        mode: "000644"
        owner: root
        group: root
        content: |
            server {

                location /assets {
                  alias /var/app/current/public/assets;
                  gzip_static on;
                  gzip on;
                  expires max;
                  add_header Cache-Control public;
                }

                location /public {
                  alias /var/app/current/public;
                  gzip_static on;
                  gzip on;
                  expires max;
                  add_header Cache-Control public;
                }

            }

# This reloads the server, which will both make the changes take affect and makes sure the config is valid when you deploy
container_commands:
  01_reload_nginx:
    command: "sudo service nginx reload"

但是我得到了这个错误:

[2017-12-13T06:23:48.635Z] ERROR [17344] : Command CMD-AppDeploy failed!
[2017-12-13T06:23:48.635Z] INFO  [17344] : Command processor returning results: 
{"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"container_command 01_reload_nginx in .ebextensions/01_elastic_beanstalk_webapp.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":7,"events":[]}]}

/var/log/eb-activity.log:

[2017-12-13T06:23:48.584Z] INFO  [17344] - [Application update fix-command-nginx-reload-hope@2/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_myapp_website/Command 01_reload_nginx] : Starting activity...
[2017-12-13T06:23:48.619Z] INFO  [17344] - [Application update fix-command-nginx-reload-hope@2/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_myapp_website/Command 01_reload_nginx] : Activity execution failed, because:  (ElasticBeanstalk::ExternalInvocationError)


[2017-12-13T06:23:48.619Z] INFO  [17344] - [Application update fix-command-nginx-reload-hope@2/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_myapp_website/Command 01_reload_nginx] : Activity failed.

虽然如果我 ssh 进入实例并执行 sudo service nginx reload 它将正常执行.. 有什么想法吗?

编辑

$ cat /proc/version
Linux version 4.9.43-17.39.amzn1.x86_64 (mockbuild@gobi-build-64011) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Fri Sep 15 23:39:41 UTC 2017

部署命令:

eb deploy my-app -v

请求资产的标题

Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/x-javascript
Date: Fri, 24 Aug 2018 11:03:50 GMT
ETag: W/"12cd8ea0-20db3"
Last-Modified: Mon, 31 Dec 1979 04:08:00 GMT
Server: nginx/1.12.1
Transfer-Encoding: chunked
Via: 1.1 8cc9957dff77c27e9931ab0aaf344ec9.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 0NlE-FiGgzczadHYeK7HMMsDsGRmaB8Sefvo89phHWw3LSx01t5rgQ==
X-Cache: Miss from cloudfront

缺少标题

   access-control-max-age: 3000
   age: 48214

服务器端的更新配置文件

$ cat /etc/nginx/conf.d/webapp.conf
server {

    location /assets {
      alias /var/app/current/public/assets;
      gzip_static on;
      gzip on;
      expires max;
      add_header Cache-Control public;
      add_header 'Access-Control-Allow-Origin' '*';
    }

    location /public {
      alias /var/app/current/public;
      gzip_static on;
      gzip on;
      expires max;
      add_header Cache-Control public;
      add_header 'Access-Control-Allow-Origin' '*';
    }

}

编辑

service nginx configtest 结果:

$ sudo service nginx configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

【问题讨论】:

  • @simo:你是通过 eb cli 部署的吗?如果是这样,您可以添加您用于部署更改的命令吗?您还可以重现错误然后运行 ​​eb 日志并将一些输出发布到您的问题吗?谢谢。
  • 是的,我使用 eb cli 部署,命令是 eb deploy my-app -v 我在上面添加了 请求资产的标头缺少的标头,请查看它们.我认为,在深入了解 container_commands 的错误之前,至少要检查为什么实际上错过了丢失的标题?因为我已经通过命令行成功重新启动了 nginx,但仍然缺少年龄标头。请检查上面的webapp.conf,如果您需要更多信息,请告诉我
  • 还有一个问题:您能解释一下 nginx 配置更改的预期目标是什么吗?
  • 我需要将 access-control-max-ageage 标头与服务资产一起传递以利用浏览器缓存

标签: amazon-web-services nginx amazon-elastic-beanstalk


【解决方案1】:

command: "sudo service nginx reload" 不是必需的,因为 NGINX 服务会在每次成功部署后自动重启。您可以将其从配置文件中删除。

您可能遇到 CDN 服务过期延迟,请尝试刷新其缓存或直接针对 EB url 进行测试。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题和错误。以前,我确实需要 container_commands 来进行设置,但是在大量升级过程中,我开始在部署过程中遇到类似的错误。最终,只需要删除 container_commands 并且一切正常。

    从您的 .ebextensions 脚本中删除此部分:

    container_commands:
      01_reload_nginx:
        command: "sudo service nginx reload"
    

    注意:你可能也想删除上面的注释行。

    【讨论】:

      猜你喜欢
      • 2019-12-27
      • 2021-08-04
      • 2019-03-28
      • 2021-03-05
      • 2021-08-27
      • 2021-10-23
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多