Install Node.js on Ubuntu 14.04
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
node --version
sudo apt-get install -y build-essential
Install strong-pm
sudo npm install -g strong-pm
sudo sl-pm-install
sudo /sbin/initctl start strong-pm
You can edit the configuration file here:
//In this file you can add env variables and change the deployment port
sudo vi /etc/init/strong-pm.conf
By default the application is deployed on this path
cd /var/lib/strong-pm/svc/1/work/current
Also you can see the application logs here:
tail -f /var/log/upstart/strong-pm.log
Install Nginx
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
With Nginx you can put you API in an specific domain intead of 3001 port, for this you need to create a config file for your domain:
sudo vi /etc/nginx/sites-available/my.domain.com
--START File content--
server {
listen 80;
server_name my.domain.com;
access_log /var/log/nginx/api_access.log;
error_log /var/log/nginx/api_error.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3001;
}
}
--END--
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location /explorer/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3001/explorer/;
}
location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3001/api/;
}
location / {
try_files $uri $uri/ =404;
}
}
After that you need to link the config file to the sites-enabled folder
sudo ln -s /etc/nginx/sites-available/my.domain.net /etc/nginx/sites-enabled/
Also you need to change this line in the nginx config file
sudo vi /etc/nginx/nginx.conf
--START File content--
server_names_hash_bucket_size 64;
--END--
Restart the nginx service
sudo service nginx restart
well done!