Nginx config file overwritten during Elastic Beanstalk deployment?

Antoine

I need to add p3p headers to the static resource location on a standard Nodejs & Nginx Elastic Beanstalk.

I've created an ebextension script as explained on this question. The script uses sed to add a add_header directive under the alias line, which is under the static location directive. It runs on the /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf file.

The script not only modifies the file, it also copies it to a "safe" location, i.e. /home/ec2-user. According to /var/log/cfn-init.log, the script runs correctly. As evidence, the copy of the modified file shows the additional header at the right place. But the /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf file does not have this modification.

I can only deduce that although my script runs fine, something else later in the deployment process overwrites it. Which is strange, because according to documentation container commands are run after the application and web server have been set up, so I don't see what does it.

So ho/what is overwriting this file and how can I prevent that?

Philip Callender

It seems that Elastic Beanstalk has changed and the commonly recommended approach/hack of overwriting #etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf doesn't work any more. Nor does creating any file in /tmp/deployment/config.

The solution I found was to overwrite /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf directly, using a container_commands directive, since these commands are executed after the Elastic Beanstalk install creates it's version of the nginx config.

From http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-container-commands:

They [container_commands] run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed.

I did this in three steps within .ebextensions:

  1. Create my version of the nginx config file.

  2. Create a script to overwrite the standard config file with my own.

  3. Run the script.

The first two steps happen earlier in the install process, while the last uses container_commands so as described previous happens late in the install.

Here's the files I used:

File .ebextensions/install_nginx_config_01.config:
(Note that the indenting is important)

#
#   STEP 1 - Create the nginx config file
#
files:

  "/tmp/my.nginx.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
      # This file was overwritten during deployment
      # by .ebextensions/install_nginx_config_03.config

      upstream nodejs {
          server 127.0.0.1:3000;
          keepalive 256;
      }

      server {
          listen 8080;

          location / {
              proxy_pass  http://nodejs;
              proxy_set_header   Connection "";
              proxy_http_version 1.1;
              proxy_set_header        Host            $host;
              proxy_set_header        X-Real-IP       $remote_addr;
              proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          }

          gzip on;
          gzip_comp_level 4;
          gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
      }

File .ebextensions/install_nginx_config_02.config:

#
#   STEP 2 - Create a script that will overwrite the Nginx config
#
files:

  "/tmp/install-nginx-config.sh" :
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/sh
      cp /tmp/my.nginx.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf

File .ebextensions/install_nginx_config_03.config:

#
#   STEP 3 - Run the script to overwrite the nginx config template.
#
container_commands:

  01_runmyshellscript:
    command: "/tmp/install-nginx-config.sh"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Running a .config file on Elastic Beanstalk?

From Dev

Elastic Beanstalk .config file on VCS?

From Dev

Elastic Beanstalk Deployment Errno 2 No Such File / Directory

From Dev

Passing .config file to AWS Elastic Beanstalk

From Dev

Elastic Beanstalk Deployment with MongoDB

From Dev

How to change nginx config in amazon elastic beanstalk running a docker instance

From Dev

Could not load file or assembly Magick.Net on Elastic Beanstalk Deployment

From Dev

Could not load file or assembly Magick.Net on Elastic Beanstalk Deployment

From Dev

Elastic beanstalk: Unhandled exception during build: [Errno 2] No such file or directory

From Dev

Config File Overwritten in Qt

From Dev

Keep config file secure using github and Elastic Beanstalk?

From Dev

Can't set AWS Elastic Beanstalk static path with config file

From Dev

AWS Elastic Beanstalk Not Recognising Valid Value In Config File

From Dev

Can't set AWS Elastic Beanstalk static path with config file

From Dev

Keep config file secure using github and Elastic Beanstalk?

From Dev

Elastic Beanstalk with Docker deployment failure

From Dev

AWS Elastic Beanstalk - Deployment Quandry

From Dev

AWS Elastic Beanstalk schedule deployment

From Dev

AWS Elastic Beanstalk Deployment Order

From Dev

elastic beanstalk weird nginx configuration

From Dev

Elastic Beanstalk Django Deployment With Preconfigured Docker Container

From Dev

Bundler:Gemfile not found preventing elastic beanstalk deployment

From Dev

Rails 4 Elastic Beanstalk deployment error

From Dev

Troubleshooting Elastic Beanstalk Node.js Deployment

From Dev

Bundler:Gemfile not found preventing elastic beanstalk deployment

From Java

How do I change file permissions on /tmp during and elastic beanstalk app deploy?

From Dev

How to access to docker config file in S3 bucket from Elastic Beanstalk instance

From Dev

Install firefox on elastic beanstalk using ebextensions config?

From Dev

Install ffmpeg on elastic beanstalk using ebextensions config

Related Related

  1. 1

    Running a .config file on Elastic Beanstalk?

  2. 2

    Elastic Beanstalk .config file on VCS?

  3. 3

    Elastic Beanstalk Deployment Errno 2 No Such File / Directory

  4. 4

    Passing .config file to AWS Elastic Beanstalk

  5. 5

    Elastic Beanstalk Deployment with MongoDB

  6. 6

    How to change nginx config in amazon elastic beanstalk running a docker instance

  7. 7

    Could not load file or assembly Magick.Net on Elastic Beanstalk Deployment

  8. 8

    Could not load file or assembly Magick.Net on Elastic Beanstalk Deployment

  9. 9

    Elastic beanstalk: Unhandled exception during build: [Errno 2] No such file or directory

  10. 10

    Config File Overwritten in Qt

  11. 11

    Keep config file secure using github and Elastic Beanstalk?

  12. 12

    Can't set AWS Elastic Beanstalk static path with config file

  13. 13

    AWS Elastic Beanstalk Not Recognising Valid Value In Config File

  14. 14

    Can't set AWS Elastic Beanstalk static path with config file

  15. 15

    Keep config file secure using github and Elastic Beanstalk?

  16. 16

    Elastic Beanstalk with Docker deployment failure

  17. 17

    AWS Elastic Beanstalk - Deployment Quandry

  18. 18

    AWS Elastic Beanstalk schedule deployment

  19. 19

    AWS Elastic Beanstalk Deployment Order

  20. 20

    elastic beanstalk weird nginx configuration

  21. 21

    Elastic Beanstalk Django Deployment With Preconfigured Docker Container

  22. 22

    Bundler:Gemfile not found preventing elastic beanstalk deployment

  23. 23

    Rails 4 Elastic Beanstalk deployment error

  24. 24

    Troubleshooting Elastic Beanstalk Node.js Deployment

  25. 25

    Bundler:Gemfile not found preventing elastic beanstalk deployment

  26. 26

    How do I change file permissions on /tmp during and elastic beanstalk app deploy?

  27. 27

    How to access to docker config file in S3 bucket from Elastic Beanstalk instance

  28. 28

    Install firefox on elastic beanstalk using ebextensions config?

  29. 29

    Install ffmpeg on elastic beanstalk using ebextensions config

HotTag

Archive