6

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.

Musa
  • 406
  • 3
  • 11
  • you entered the instance by ssh and verified that the file wasn't created? or is just that the config on nginx aren't beign updated? – xploshioOn Apr 13 '20 at 07:37
  • anyways, I am checking on another project that we do something like that, the only difference is that we don't specify `mode`, `owner` and `group`, the folder is ...conf.d/file.conf, so we don't have another folder on conf.d, and we run `service nginx reload` without sudo, try changing these and see if that works for you, it's the only difference that we have with a working file – xploshioOn Apr 13 '20 at 07:38
  • did you ever get a real answer @Musa? I'd also like to not user `sed`, and the AWS documentation apparently does not work (at least for AL2) -> https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-files which is exactly what you've tried – Nick Brady Jul 29 '20 at 17:11
  • 1
    Did anyone figure this out? Please share your answer because I'm struggling too – Hawaiian Pizza Mar 25 '22 at 00:09

3 Answers3

1

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.

Nick Brady
  • 6,084
  • 1
  • 46
  • 71
0

Try to simply put this file into .ebextensions/nginx/conf.d/elasticbeanstalk without a script.

At least this is how the Java SE platform works: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html. I don't think this is different for PHP.

Also on your EC2 instace check the output of log files (cfn-init.log, cfn-init-cmd.log etc.).

Balázs Németh
  • 6,222
  • 9
  • 45
  • 60
  • 1
    I tried your method, but that doesn't seem to work either. I check the `/var/log/cfn-init.log` file and it said "reload-nginx" command succeeded. So it is in fact running the reload command, however the file is not generated. – Musa Apr 11 '20 at 11:36
0

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
shariqmaws
  • 8,152
  • 1
  • 16
  • 35
  • 1
    The documentation you linked is targeted at Node, not to mention it's pretty much the same as what I have right now... I'd prefer not to to use sed. – Musa Apr 12 '20 at 09:17