Skip to content

Instantly share code, notes, and snippets.

@icidasset
Last active October 5, 2022 17:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icidasset/931e80e72eee4c0d6aeafb6409b00cf8 to your computer and use it in GitHub Desktop.
Save icidasset/931e80e72eee4c0d6aeafb6409b00cf8 to your computer and use it in GitHub Desktop.
AWS Beanstalk Nginx Configuration
files:
"/etc/sysctl.d/99_networking.conf":
mode: "000644"
owner: root
group: root
content: |
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
"/etc/security/limits.conf":
mode: "000644"
encoding: plain
owner: root
group: root
content: |
# THIS FILE HAS BEEN MODIFIED BY AN `.ebextensions` SCRIPT
* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535
container_commands:
01_reload_nginx:
command: "sudo service nginx reload"
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
# Max amount of open files
worker_rlimit_nofile 65535;
# Events
events {
worker_connections 8192;
use epoll;
}
########
# HTTP #
########
http {
# Logs
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format healthd '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
access_log /var/log/nginx/access.log main;
# Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 250M;
# Mime types
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Upstream
upstream application_interface {
server unix:///var/run/puma/my_app.sock fail_timeout=300s max_fails=3 max_conns=0;
}
# Index
index index.html index.htm;
# Server
# ======
server {
listen 80 backlog=16384 default_server;
server_name _ localhost; # need to listen to localhost for worker tier
# Time
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
# Logs
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
# Locations
location / {
proxy_pass http://application_interface;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /assets {
alias /var/app/current/public/assets;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
location /public {
alias /var/app/current/public;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
# EBS
# ---
include conf.d/elasticbeanstalk/*.conf;
}
}
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15741
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 15741
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment