Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modify nginx proxy settings in Elastic Beanstalk options
files:
"/tmp/proxy.conf":
mode: "000644"
owner: root
group: root
content: |
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
container_commands:
00-add-config:
command: cat /tmp/proxy.conf >> /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
01-restart-nginx:
command: /sbin/service nginx restart
@zerebral

This comment has been minimized.

Copy link

@zerebral zerebral commented Dec 7, 2016

The settings work fine - but on subsequent deployments the same content gets appended in the conf file. The add config command should be -

command: cat /tmp/proxy.conf > /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf

@tzachshabtay

This comment has been minimized.

Copy link

@tzachshabtay tzachshabtay commented Jun 29, 2017

Hmm, so when I use this as is, the file is indeed modified, but I get an error on the nginx restart:

Command failed on instance. Return code: 137 Output: Stopping nginx: /sbin/service: line 66: 23734 Killed env -i PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}.

If I either change nginx restart to nginx reload, or add an "ignoreErrors" to the restart-nginx command, then the deploy passes, but the configuration file is not modified. This seems to imply that the container_commands is running too early.

Any clue?

EDIT: Ok, managed to solve it with a post deploy folder hook. So my script looks like this (put my nginx cofig file in my app root):


files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/90_copy_nginx_config.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
        #!/usr/bin/env bash
        cat /var/app/current/00_elastic_beanstalk_proxy.conf > /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
        /sbin/service nginx reload

@NathanKun

This comment has been minimized.

Copy link

@NathanKun NathanKun commented Sep 13, 2021

According to the doc https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
Now we should place the nginx conf files in .platform/nginx

|-- web.jar
|-- .ebextensions/
|-- .platform/
    |-- nginx/                # Proxy configuration
    |   |-- nginx.conf
    |   `-- conf.d/
    |       `-- custom.conf

This is actually a lot easier because aws will copy nginx conf files and reload nginx process automaticlly so that we don't need to write any command.

Tested at Sept 2021.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment