Created
February 13, 2017 15:23
-
-
Save albacoretuna/aaae08617729d26fce52024cafb59e12 to your computer and use it in GitHub Desktop.
Nginx configuration for aws beanstalk, enables gzip, sets up node proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# All nginx configurations can go here | |
files: | |
# This creates a file at the address below on the beanstalk instance | |
/etc/nginx/conf.d/proxy.conf: | |
mode: "000644" | |
owner: root | |
group: root | |
content: | | |
upstream nodejs { | |
server 127.0.0.1:8081; | |
keepalive 256; | |
} | |
# 8080 set by AWS | |
server { | |
listen 8080; | |
# maximum file size for image uploads | |
client_max_body_size 10M; | |
# internal log handling by AWS | |
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { | |
set $year $1; | |
set $month $2; | |
set $day $3; | |
set $hour $4; | |
} | |
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; | |
access_log /var/log/nginx/access.log main; | |
# path to static files | |
root /var/app/current/dist/client; | |
# First match requests to files, if not found forward it to nodejs | |
location / { | |
try_files $uri $uri/ @backend; | |
} | |
location @backend { | |
proxy_pass http://nodejs; | |
proxy_set_header Connection ""; | |
proxy_http_version 1.1; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
# Enabling compression | |
gzip on; | |
gzip_comp_level 4; | |
gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript; | |
} | |
option_settings: | |
- option_name: NPM_CONFIG_PRODUCTION | |
value: true | |
option_name: NodeCommand | |
value: "npm start" | |
container_commands: | |
# remove the default nginx config files from beanstalk | |
removeconfig: | |
command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment