Docker的Elastic Beanstalk,Nginx配置

时间:2019-05-07 09:28:50

标签: docker nginx amazon-elastic-beanstalk

我有一个在Elastic Beanstalk上工作的应用程序。该应用程序导出Docker容器的两个端口。 Nginx只采用第一个,因此我必须更改配置以添加另一个。

this postAWS documentation之后,我试图扩展nginx配置以添加另一个上游,因此我创建了进一步的文件来做到这一点:

files:
  "/etc/nginx/conf.d/api-port.conf":
    mode: "000644"
    owner: root
    group: root
    content: |

      upstream docker {
        server 172.17.0.2:4003;
        keepalive 256;
      }

      server {
          listen 4003;

        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
          set $year $1;
          set $month $2;
          set $day $3;
          set $hour $4;
        }
          access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;

        access_log    /var/log/nginx/access.log;

        location / {
          proxy_pass            http://docker;
          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;
        }
      }

此文件已部署在文件夹.ebextensions/nginx/conf.d/api-port.conf中,并已复制到EC2实例,但它不起作用,也未复制到/etc/nginx/conf.d

有什么想法吗?

预先感谢

2 个答案:

答案 0 :(得分:0)

您是否已将此内容包含在Docker配置中:

如果您使用Dockerfile,请使用:

COPY /path/to/api-port.conf /etc/nginx/conf.d/

如果您使用docer-compose.yml:

volumes:
  - ./path/to/api-port.conf:/etc/nginx/conf.d/api-port.conf

无论如何,如果您发布docker配置文件将会更有帮助

答案 1 :(得分:0)

您可能希望将文件从.ebextensions/nginx/conf.d/api-port.conf移到.ebextensions/api-port.config。这样可以修复未复制到/etc/nginx/conf.d

的文件