Last active
May 14, 2020 06:36
-
-
Save snmmaurya/e26bb9cdcd906a0a90be886edb73bc46 to your computer and use it in GitHub Desktop.
How to deploy node application on AWS beanstalk (proxy - NGINX)
This file contains 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
container_commands: | |
00_node_binary: | |
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node" | |
00_npm_binary: | |
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm" | |
50-run-database-migrations: | |
command: "./node_modules/.bin/sequelize db:migrate" | |
leader_only: true |
This file contains 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
AWS configuration | |
Create beankstalk environment | |
Node Application configuration | |
package.json change "scripts" key's value | |
Create .ebextensions directory at root | |
create two files inside .ebextensions to enable node and sequelize (migration) and proxy(NGINX) - | |
1) master.config | |
2) proxy.config |
This file contains 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
{ | |
"name": "mobikwik", | |
"version": "1.0.0", | |
"description": "PG", | |
"main": "dist/starter.js", | |
"scripts": { | |
"compile": "tsc -w", | |
"compile-once": "tsc", | |
"start": "nodemon tsc && dist/starter.js", | |
"server": "node tsc && dist/starter.js", | |
"staging": "tsc && pm2-runtime start ecosystem.config.js --env staging", | |
"production": "tsc && pm2-runtime start ecosystem.config.js --env production" | |
}, | |
"author": "Snm Maurya", | |
"license": "ISC", | |
"dependencies": { | |
"body-parser": "^1.19.0", | |
"crypto": "^1.0.1", | |
"crypto-js": "^4.0.0", | |
"dotenv": "^8.2.0", | |
"express": "^4.17.1", | |
"fast-xml-parser": "^3.16.0", | |
"pg": "^8.0.3", | |
"pg-hstore": "^2.3.3", | |
"pm2": "^4.2.3", | |
"sequelize": "^5.21.6", | |
"sequelize-cli": "^5.5.1", | |
"typescript": "^3.8.3" | |
} | |
} |
This file contains 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
files: | |
/etc/nginx/conf.d/proxy.conf: | |
mode: "000644" | |
owner: root | |
group: root | |
content: | | |
upstream nodeapi { | |
server 127.0.0.1:5000; | |
keepalive 256; | |
} | |
server { | |
listen 8080 ; | |
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; | |
location / { | |
proxy_pass http://nodeapi; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
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; | |
} | |
gzip on; | |
gzip_comp_level 4; | |
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
location /static { | |
alias /var/app/current/static; | |
} | |
} | |
container_commands: | |
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