One of the biggest issues with Elastic Beanstalk is the default configuration it comes with. When I released the initial documentation on how to do this, you needed to login with ssh into the server right after server deploy using triggers. Now it is much easier to do so using ebextensions.
Part of your deploy, you can add a directory with Elastic Beanstalk extensions. First, simply add a directory called .ebextensions
. Now add YAML config files to it using the following format:
packages:
name of package manager:
package name: version
groups:
name of group: {}
name of group:
gid: "group id"
users:
name of user:
groups:
- name of group
uid: "id of the user"
homeDir: "user's home directory"
sources:
target directory: location of archive file
files:
"target file location on disk":
mode: "six-digit octal value"
owner: name of owning user for file
group: name of owning group for file
source: URL
authentication: authentication name:
"target file location on disk":
mode: "six-digit octal value"
owner: name of owning user for file
group: name of owning group for file
content: |
this is my content
encoding: encoding format
authentication: authentication name:
commands: #Note these run prior to services starting etc
command name:
command: command to run
cwd: working directory
env:
variable name: variable value
test: conditions for command
ignoreErrors: true
services:
sysvinit:
name of service:
enabled: "true"
ensureRunning: "true"
files:
- "file name"
sources:
- "directory"
packages:
name of package manager:
"package name[: version]"
commands:
- "name of command"
container_commands:
name of container_command:
command: "command to run"
leader_only: true
name of container_command:
command: "command to run"
Inside of the .ebextensions directory, files added run in alphabetic / numerical order and should have the .config
extension.
A much used snippet for changing settings for nginx (after installation) to fix issues with 413 Request Entity Too Large
:
container_commands:
01_reload_nginx:
command: "sudo service nginx reload"
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 100M;
This will create a file called proxy.conf and reload the nginx config every time you do a deploy. As per the default nginx settings, all *.conf
file gets loaded.
Other proxy settings which I normally adjust are:
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
Note that some of these settings only work in conjunction with classic elastic load-balancer in tcp mode as the application load-balancer is a reverse-proxy as well! As for the config files, you could also make changes to nginx by using sed replacing using container_commands
. You can also replace the entire file by overwriting the entire file and restarting the service afterwards. Container commands run after the webserver is set up while commands run prior to webserver setup.
For more info, please consult the reference material at AWS