diff --git a/.ebextensions/node-settings.config b/.ebextensions/node-settings.config new file mode 100644 index 0000000..1632114 --- /dev/null +++ b/.ebextensions/node-settings.config @@ -0,0 +1,3 @@ +option_settings: + aws:elasticbeanstalk:container:nodejs: + NodeCommand: "npm run-script prod" \ No newline at end of file diff --git a/.ebextensions/proxy.config b/.ebextensions/proxy.config new file mode 100644 index 0000000..11070a6 --- /dev/null +++ b/.ebextensions/proxy.config @@ -0,0 +1,66 @@ +files: + /etc/nginx/conf.d/proxy.conf: + mode: "000644" + owner: root + group: root + content: | + upstream nodejs { + server 127.0.0.1:8081; + 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 /socket.io/ { + proxy_pass http://nodejs; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location / { + proxy_pass http://nodejs; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + 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; + } + + } + + /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh: + mode: "000755" + owner: root + group: root + content: | + #!/bin/bash -xe + rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf + service nginx stop + service nginx start + +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" \ No newline at end of file diff --git a/.gitignore b/.gitignore index fa7e9cf..3947ab5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ node_modules npm-debug.log src/public/main.js src/.secret + +# Elastic Beanstalk Files +.elasticbeanstalk/* +!.elasticbeanstalk/*.cfg.yml +!.elasticbeanstalk/*.global.yml diff --git a/package.json b/package.json index fd8c3ec..79837f9 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ }, "scripts": { "start": "node index.js", - "prod": "npm run bundle && forever start -c \"npm start\" ./", + "prod": "npm run bundle && npm run start", "dev": "npm run bundle && gulp start", "bundle": "gulp bundle", "test": "npm run bundle && gulp test",