Last active
August 29, 2015 14:12
-
-
Save BlakePetersen/e9b1c1e7d10080d3613a to your computer and use it in GitHub Desktop.
Vagrant - Ubuntu 14.04/nginx/Forever/SailsJS
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
#!/usr/bin/env bash | |
###### -- Installs NodeJS/npm, SailsJS, Forever, and nginx. It then configures nginx to proxy out via 80 for localhost:1337, the default SailsJS port | |
### Update Packages | |
apt-get update | |
### Install NodeJS/npm | |
echo -e '\n-=-=- Installing Node...' | |
apt-get -y install g++ curl libssl-dev apache2-utils | |
apt-get -y install git-core | |
git clone git://github.com/joyent/node.git | |
cd node | |
./configure | |
make > /dev/null | |
sudo make install > /dev/null | |
cd .. | |
### Install SailsJS and Forever via npm | |
echo -e '\n-=-=- Installing SailsJS and Forever...' | |
sudo npm -gs install sails | |
sudo npm -gs install forever | |
### Install nginx | |
echo -e '\n-=-=- Installing nginx...' | |
apt-get -y install nginx > /dev/null | |
### Configure Virtual Hosts | |
echo -e '\n-=-=- Configuring Virtual Hosts...' | |
# Remove the Default | |
sudo rm /etc/nginx/sites-available/default | |
sudo rm /etc/nginx/sites-enabled/default | |
# Create SailsJS specific (port 1337), WebSockets-friendly Virtual Hosts Entry | |
echo ' | |
upstream sails { | |
server 127.0.0.1:1337; | |
keepalive 256; # not necessary | |
} | |
server { | |
listen 80; | |
server_name vagrant.sailsjs; | |
access_log /var/log/nginx/vagrant.sailsjs.access.log; | |
error_log /var/log/nginx/vagrant.sailsjs.error.log; | |
large_client_header_buffers 8 32k; | |
location / { | |
# the following is required for WebSockets | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_buffers 8 32k; | |
proxy_buffer_size 64k; | |
# the following is required | |
proxy_pass http://sails; | |
proxy_redirect off; | |
# the following is required as well for WebSockets | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
tcp_nodelay on; # not necessary | |
} | |
} | |
' > /etc/nginx/sites-available/vagrant.sailsjs | |
# Symlink into 'Sites Enabled | |
ln -s /etc/nginx/sites-available/vagrant.sailsjs /etc/nginx/sites-enabled/vagrant.sailsjs | |
# Restart nginx | |
service nginx stop | |
service nginx start | |
# Add entry to Hosts | |
echo '127.0.0.1 vagrant.sailsjs' >> /etc/hosts | |
### Fire up forever targetting our Sails app, applying a watch directive to restart when files changes are detected | |
echo -e '\n-=-=- All set, lift the sails!' | |
forever start -w /vagrant/app.js |
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
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.provision :shell, path: "bootstrap.sh" | |
config.vm.network :forwarded_port, host: 4567, guest: 80 | |
config.vm.provider "virtualbox" do |v| | |
v.name = "SailsJS Vagrant Instance" | |
v.customize ["modifyvm", :id, "--memory", "2048"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment