Skip to content

Instantly share code, notes, and snippets.

@jayjariwala
Last active December 22, 2017 15:44
Show Gist options
  • Save jayjariwala/94681a9a6a94a0b41f74660da612e7bb to your computer and use it in GitHub Desktop.
Save jayjariwala/94681a9a6a94a0b41f74660da612e7bb to your computer and use it in GitHub Desktop.
Steps to get up and running with node js server using nginx reverse proxy
sudo apt-get install finger
sudo apt-get install openssh-server openssh-client
change ssh port if necessary: /etc/ssh/sshd_condig
sudo adduser student
#Give Sudo Privilages to the new user
visudo
# User privilege specification
newuser ALL=(ALL:ALL) ALL
#Install nodejs server and manage it using nginx
sudo apt-get update
sudo apt-get install ng
#Configure the firewall
-- registed applist on nginx
sudo ufw app list
sudo ufw allow ssh
sudo ufw allow 'Nginx HTTP'
sudo ufw enable
systemctl status nginx
ip addr show // check ip addr and ping to see if the nginx page is up and running.
#Mange Nginx process
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl disable nginx
sudo systemctl enable nginx
#configure server block
By Default Server block on ubuntu: /var/www/html
sudo mkdir -p /var/www/example.com/html
sudo mkdir -p /var/www/test.com/html
#change permission of the directory
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/test.com/html
sudo chmod -R 755 /var/www
#assign html files
nano /var/www/example.com/html/index.html
nano /var/www/test.com/html/index.html
#create server blocks to tell nginx on how and when to serve these pages.
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
#Enable your Server Blocks and Restart Nginx
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/
sudo nano /etc/nginx/nginx.conf
server_names_hash_bucket_size 64; //uncomment the line to avoid hash bucket memory problem
sudo nginx -t // check for nginx error if it is ok move forward...
sudo systemctl restart nginx
#NODE JS PROJECT SETUP AND SERVE
#Install Node.js
cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
sudo apt-get install build-essential
#Install mongodb as a service
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
||| TO SHUTDOWN THE SERVER |||
shutdown -h 5 // shut it down after 5 mins
shutdown -h now // now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment