Skip to content

Instantly share code, notes, and snippets.

@123ish
Created September 26, 2020 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 123ish/dea083b0181b5a3b114b34c3975623f9 to your computer and use it in GitHub Desktop.
Save 123ish/dea083b0181b5a3b114b34c3975623f9 to your computer and use it in GitHub Desktop.
.platform/nginx/conf.d/00_rate_limit.conf
# Example of nginx configulation file for AL2 Amazon Elastic Beanstalk
# your vpc subnet where ELB resides in
set_real_ip_from 10.0.0.0/8;
# Then you have the configuration like this. Please note real_ip_header and real_ip_recursive have
# to be placed in the bottom of the IP list otherwise the module will not work properly(I’ve spent so much time on this).
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# limit the number of connections to 30 per min and allow to burst to 10
limit_req_zone $http_x_forwarded_for zone=application:10m rate=5r/m;
limit_req zone=application burst=10 nodelay;
limit_req_status 429;
limit_conn_status 429;
error_page 429 /429;
# Example of the old nginx configulation file for Amazon Linux 2018 Amazon Elastic Beanstalk
files:
"/etc/nginx/conf.d/01b_rate-limit.conf":
owner: root
group: root
mode: "000644"
content: |
# your vpc subnet where ELB resides in
set_real_ip_from 10.0.0.0/8;
# Then you have the configuration like this. Please note real_ip_header and real_ip_recursive have
# to be placed in the bottom of the IP list otherwise the module will not work properly(I’ve spent so much time on this).
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# limit the number of connections to 30 per min and allow to burst to 10
limit_req_zone $http_x_forwarded_for zone=application:10m rate=5r/m;
limit_req zone=application burst=10 nodelay;
limit_req_status 429;
limit_conn_status 429;
error_page 429 /429;
container_commands:
02_reload_nginx:
command: "sudo service nginx reload"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment