Created
July 17, 2019 22:41
-
-
Save jwchang0206/10b67a7cef6c2bbb21daf6e6931d6c62 to your computer and use it in GitHub Desktop.
Docker nginx & node.js app
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 fholzer/nginx-brotli:latest | |
COPY nginx.conf /etc/nginx/nginx.conf | |
EXPOSE 80 | |
CMD ["nginx", "-g", "daemon off;"] |
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 node:10-alpine | |
# Install pm2 | |
RUN npm install pm2 -g | |
# Expose ports needed to use Keymetrics.io | |
EXPOSE 80 443 43554 | |
# Mount volume | |
VOLUME ["/usr/src/app/public"] | |
# Environment variables | |
ENV NODE_ENV production | |
ENV PORT 3000 | |
# For installing native modules | |
RUN apk add --no-cache make gcc g++ python git | |
# Set a working directory | |
WORKDIR /usr/src/app | |
COPY ./build/package.json . | |
COPY ./build/yarn.lock . | |
# Install Node.js dependencies | |
RUN yarn install --production --no-progress | |
# Copy application files | |
COPY ./build . | |
# Show current folder structure in logs | |
RUN ls -al -R | |
EXPOSE 3000 | |
CMD [ "pm2-docker", "start", "process-web.json" ] |
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
worker_processes auto; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
include /etc/nginx/mime.types; | |
gzip on; | |
gzip_vary on; | |
gzip_proxied any; | |
gzip_comp_level 2; | |
gzip_min_length 860; | |
gzip_buffers 16 8k; | |
gzip_http_version 1.1; | |
gzip_types | |
text/css | |
text/plain | |
text/javascript | |
application/javascript | |
application/json | |
application/x-javascript | |
application/xml | |
application/xml+rss | |
application/xhtml+xml | |
application/x-font-ttf | |
application/x-font-opentype | |
application/vnd.ms-fontobject | |
image/svg+xml | |
image/x-icon | |
application/rss+xml | |
application/atom_xml; | |
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; | |
brotli on; | |
brotli_types | |
text/css | |
text/plain | |
text/javascript | |
application/javascript | |
application/json | |
application/x-javascript | |
application/xml | |
application/xml+rss | |
application/xhtml+xml | |
application/x-font-ttf | |
application/x-font-opentype | |
application/vnd.ms-fontobject | |
image/svg+xml | |
image/x-icon | |
application/rss+xml | |
application/atom_xml; | |
brotli_comp_level 4; | |
brotli_min_length 860; | |
server { | |
listen 80; | |
server_name _; | |
if ($http_x_forwarded_proto = 'http') { | |
return 301 https://$host$request_uri; | |
} | |
location / { | |
gzip_static on; | |
brotli_static on; | |
root /usr/src/app/public; | |
expires 30m; | |
add_header Cache-Control public; | |
access_log off; | |
try_files $uri @app; | |
} | |
location @app { | |
proxy_redirect off; | |
proxy_pass http://app:3000; | |
proxy_set_header Host $host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment