Elastic Beanstalk: `.ebextensions` not getting executed

Viewed 2827

I'm deploying a PHP application to Beanstalk and all appears to be fine, however my .ebextensions configuration files don't seem to be running.

I have just a single configuration file that is supposed to create a file, and then reload nginx.
/my-project/.ebextensions/nginx.config:

files:
  "/etc/nginx/conf.d/elasticbeanstalk/extend-nginx.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
      add_header X-Frame-Options "SAMEORIGIN";
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Content-Type-Options "nosniff";

      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }

container_commands:
    reload_nginx:
        command: "sudo service nginx reload"

My architecture is currently:
1. CodePipeline hooked up to GitHub that deploys the app to CodeDeploy everytime master is updated.
2. CodeDeploy receives the deployment from CodePipeline.
3. CodeDeploy installs it to the Elastic Beanstalk instance.

All the above steps work fine. I just don't understand why the config file in .ebextensions is not creating the file as expected.

Note: I have confirmed that the .ebextensions folder is in the root of the revision .zip by manually downloading one of the revisions and checking.

3 Answers

For me I was confused why a file I was trying to create was not showing up when I was deploying. The deployment had an error, and the system would automatically delete the file due to the error instead of letting it persist while rolling back to it's previous state on failure. This gave me the false notion that the file was never created in the first place.

I was able to determine this from /var/log/nginx/error.log which gave the following:

2020/07/29 20:11:36 [emerg] 23006#0: "gzip" directive is duplicate in /var/proxy/staging/nginx/conf.d/elasticbeanstalk/gzip.conf:1

which meant at least for me, I needed to override nginx.conf instead of adding a configuration file. Make sure that you aren't getting errors with your deployment if you're not seeing a file get created.

Can I refer you to the following link which describes the official way to configure the nginx reverse proxy on EB environments:

[1] Configuring the proxy server - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html

Another option is to use 'sed' like command to update the nginx configuration in place, as follows:

container_commands:
    enable_websockets:
        command: |
            sed -i '/\s*proxy_set_header\s*Connection/c \
                    proxy_set_header Upgrade $http_upgrade;\
                    proxy_set_header Connection "upgrade";\
            ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
Related