Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Beanstalk部署忽略.ebextensions中的my nginx配置文件_Amazon Web Services_Nginx_Amazon Elastic Beanstalk - Fatal编程技术网

Amazon web services Beanstalk部署忽略.ebextensions中的my nginx配置文件

Amazon web services Beanstalk部署忽略.ebextensions中的my nginx配置文件,amazon-web-services,nginx,amazon-elastic-beanstalk,Amazon Web Services,Nginx,Amazon Elastic Beanstalk,我在单个实例Elastic Beanstalk环境中托管Java webapp,并添加了几个ebextension文件,这些文件在每次部署时都成功地为我创建了配置文件。但是,我无法找到一种方法让Beanstalk在/etc/nginx或/etc/nginx/conf.d目录中添加新配置 我遵循了这里描述的步骤: 我的部署包结构如下所示: $ zip -r deploy.zip api-1.0-SNAPSHOT-all.jar .ebextensions adding: api-1.0-SNA

我在单个实例Elastic Beanstalk环境中托管Java webapp,并添加了几个ebextension文件,这些文件在每次部署时都成功地为我创建了配置文件。但是,我无法找到一种方法让Beanstalk在
/etc/nginx
/etc/nginx/conf.d
目录中添加新配置

我遵循了这里描述的步骤:

我的部署包结构如下所示:

$ zip -r deploy.zip api-1.0-SNAPSHOT-all.jar .ebextensions
  adding: api-1.0-SNAPSHOT-all.jar (deflated 11%)
  adding: .ebextensions/ (stored 0%)
  adding: .ebextensions/ssl-certificates.config (deflated 37%)
  adding: .ebextensions/https-instance-securitygroup.config (deflated 38%)
  adding: .ebextensions/nginx/ (stored 0%)
  adding: .ebextensions/nginx/conf.d/ (stored 0%)
  adding: .ebextensions/nginx/conf.d/https.conf (deflated 61%)
files:
  /home/ec2-user/https.conf:
    content: |
      server {
        listen       443;
        server_name  localhost;

        ssl                  on;
        ssl_certificate      /etc/pki/tls/certs/server.crt;
        ssl_certificate_key  /etc/pki/tls/certs/server.key;

        ssl_session_timeout  5m;

        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers   on;

        location / {
          proxy_pass  http://localhost:5000;
          proxy_http_version 1.1;
          proxy_set_header    Connection          $connection_upgrade;
          proxy_set_header    Upgrade             $http_upgrade;
          proxy_set_header    Host                $host;
          proxy_set_header    X-Real-IP           $remote_addr;
          proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
          proxy_set_header    X-Forwarded-Proto   https;
        }
      }
我的文件几乎是上述指南中样本的1:1副本

在部署期间,我的
*.config
文件都成功执行,但
/etc/nginx/conf.d/https.conf
文件丢失。我试图通过删除
.ebextensions/nginx
目录并将其替换为另一个创建
/etc/nginx/conf.d/https.conf
.config
文件来解决这个问题,但这没有帮助,文件仍然丢失

我用ssh连接到我的EC2实例上,下面是我在
/var/log/eb engine.log
中找到的内容:

2020/05/03 19:42:37.754375 [INFO] Executing instruction: configure proxy Nginx
2020/05/03 19:42:37.754393 [WARN] skipping nginx folder under .ebextensions
2020/05/03 19:42:37.754670 [INFO] No plugin in cfn metadata.

我觉得我可能错过了一些非常明显的东西,但令人惊讶的是,我找不到任何解决问题的方法。思想?谢谢

我觉得我是互联网上唯一有这个问题的人。;-)

在进一步挖掘日志之后,我意识到Beanstalk只是在部署过程的最后覆盖了我的nginx配置。这意味着创建的所有文件my
.ebextensions
都丢失了

我还没有找到一个“合适”的解决方案,但我用postdeploy钩子解决了这个问题。我的nginx配置文件现在在
/home/ec2 user
中生成,而不是
/etc/nginx
,如下所示:

$ zip -r deploy.zip api-1.0-SNAPSHOT-all.jar .ebextensions
  adding: api-1.0-SNAPSHOT-all.jar (deflated 11%)
  adding: .ebextensions/ (stored 0%)
  adding: .ebextensions/ssl-certificates.config (deflated 37%)
  adding: .ebextensions/https-instance-securitygroup.config (deflated 38%)
  adding: .ebextensions/nginx/ (stored 0%)
  adding: .ebextensions/nginx/conf.d/ (stored 0%)
  adding: .ebextensions/nginx/conf.d/https.conf (deflated 61%)
files:
  /home/ec2-user/https.conf:
    content: |
      server {
        listen       443;
        server_name  localhost;

        ssl                  on;
        ssl_certificate      /etc/pki/tls/certs/server.crt;
        ssl_certificate_key  /etc/pki/tls/certs/server.key;

        ssl_session_timeout  5m;

        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers   on;

        location / {
          proxy_pass  http://localhost:5000;
          proxy_http_version 1.1;
          proxy_set_header    Connection          $connection_upgrade;
          proxy_set_header    Upgrade             $http_upgrade;
          proxy_set_header    Host                $host;
          proxy_set_header    X-Real-IP           $remote_addr;
          proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
          proxy_set_header    X-Forwarded-Proto   https;
        }
      }
然后在
.platform/hooks/postdeploy/99\u hack\u nginx.sh
中(确保此目录包含在部署包中,方法与
.ebextensions
相同):

确保其具有正确的模式:

chmod +x .platform/hooks/postdeploy/99_hack_nginx.sh

部署,并享受您的HTTPS流量。

我刚刚解决了同样的问题

通过配置以下目录结构,可以轻松解决此问题

~/my-app/
|-- readme.md
|-- .ebextensions/
|   |-- options.config       # Option settings
|   -- cloudwatch.config     # Other .ebextensions sections, for example 
-- .platform/
    -- nginx/                # Proxy configuration
        |-- nginx.conf
        -- conf.d/
            -- custom.conf
            -- elasticbeanstalk
               |-- server.conf
有关更多信息,请参见此

my/var/log/eb-engine.log显示了下面的消息行

Running command /bin/sh -c cp -rp /var/app/staging/.platform/nginx/. /var/proxy/staging/nginx

我也面临同样的问题。 解决方案是将https.conf文件放在路径
.platform/nginx/conf.d/https.conf
中,并将其压缩到部署包中


请参阅本文中的“反向代理配置”。

这看起来比我的解决方案优雅得多,谢谢!今晚晚些时候我会运行它,如果它能运行,我会接受它。令人沮丧的是,AWS的文档似乎落后于它的实际平台。这就是答案-我通过了至少100篇文章,花了72个小时来解决这个简单的问题。@yuya.tajima我正试图像你一样扩展nginx配置,但它不起作用,至少对我来说。正如文档所述,应该将.platform/nginx/复制到/etc/nginx/conf.d(其中nginx-config是)中,但它没有。你能解释一下你是否做了其他改变吗?它还在工作吗?我正在考虑使用buildfiles复制这些文件,以重申@andrewoodleyjr,这应该是正确的答案。非常感谢。我也有同样的问题…我们两个都有。你找到了更优雅的解决方案吗?正确的解决方案是@yuya.tajima和Sivelli写的。将https.conf放在.platform/nginx/conf.d/中,然后可以删除postdeploy钩子和ebextensions中的代码。最近,我发现Beanstalk通过在Elastic Beanstalk>Environments>“env name”>Configuration>软件中更改环境变量来重新启动webapp,从而删除自定义的ngixn配置文件。你们在ngixn配置丢失的地方也有同样的问题吗?