-
-
Save caocuong2404/19392f37753f079a6043463394ec87ad to your computer and use it in GitHub Desktop.
nginx envsubst escape $
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
FROM nginx:alpine | |
# https://thepracticalsysadmin.com/templated-nginx-configuration-with-bash-and-docker/ | |
ENV LISTEN_PORT=80 \ | |
NGINX_ENV=production \ | |
SERVER_NAME=_ \ | |
RESOLVER=8.8.8.8 \ | |
UPSTREAM_API=api:3000 \ | |
UPSTREAM_API_PROTO=http \ | |
WORKDIR=/www \ | |
ESC='$' | |
WORKDIR ${WORKDIR} | |
COPY . . | |
COPY nginx.production.template /etc/nginx/nginx.production.template | |
COPY nginx.development.template /etc/nginx/nginx.development.template | |
EXPOSE ${LISTEN_PORT} | |
CMD /bin/sh -c "envsubst < ${WORKDIR}/nginx.${NGINX_ENV}.template > /etc/nginx/nginx.conf && nginx -g 'daemon off;' || cat /etc/nginx/nginx.conf" |
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
events {} | |
http { | |
error_log stderr; | |
access_log /dev/stdout; | |
upstream upstream_api { | |
server ${UPSTREAM_API}; | |
} | |
upstream upstream_webpack { | |
server ${UPSTREAM_WEBPACK}; | |
} | |
server { | |
listen ${LISTEN_PORT}; | |
server_name ${SERVER_NAME}; | |
resolver ${RESOLVER}; | |
# gzip configuration | |
gzip on; | |
gzip_disable "msie6"; | |
gzip_comp_level 6; | |
gzip_min_length 1100; | |
gzip_buffers 16 8k; | |
gzip_proxied any; | |
gzip_types | |
# text/html is always compressed by HttpGzipModule | |
text/css | |
text/javascript | |
text/xml | |
text/plain | |
text/x-component | |
application/javascript | |
application/json | |
application/xml | |
application/rss+xml | |
font/truetype | |
font/opentype | |
application/vnd.ms-fontobject | |
image/svg+xml; | |
# Allow injecting extra configuration into the server block | |
${SERVER_EXTRA_CONF} | |
# define the public application root | |
root ${WORKDIR}/public; | |
index index.html; | |
# deny requests for files that should never be accessed | |
location ~ /\. { | |
deny all; | |
} | |
location ~* ^.+\.(rb|log)$ { | |
deny all; | |
} | |
# send non-static file requests to the app server | |
location ~* \/(_live|_ready|_before|_travel_to|_travel_back|graphql|validators|notifications) { | |
try_files ${ESC}uri @api; | |
expires -1; | |
break; | |
} | |
# serve everything else via webpack | |
location / { | |
rewrite ^(.*)$ / break; | |
try_files ${ESC}uri @webpack; | |
expires -1; | |
} | |
location @api { | |
proxy_set_header X-Real-IP ${ESC}remote_addr; | |
proxy_set_header X-Forwarded-For ${ESC}proxy_add_x_forwarded_for; | |
proxy_set_header Host ${ESC}http_host; | |
proxy_redirect off; | |
proxy_pass ${UPSTREAM_API_PROTO}://upstream_api; | |
} | |
location @webpack { | |
proxy_redirect off; | |
proxy_pass ${UPSTREAM_WEBPACK_PROTO}://upstream_webpack; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment