Are you looking for a reliable VPS service? Try Vultr! With top-notch performance and a wide range of server locations, Vultr makes it easy to deploy your applications.
Example: Ubuntu 22.04. I will be using the root user, but would suggest creating a new user.
curl -sL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt install nodejs node --version
There are a few ways to get your files onto the server. I suggest using Git:
git clone yourproject.git
cd yourproject npm install npm start # Stop the app ctrl+C
sudo npm i pm2 -g pm2 start app # Other pm2 commands pm2 show app pm2 status pm2 restart app pm2 stop app pm2 logs pm2 flush # To make sure app starts when reboot pm2 startup ubuntu
You should now be able to access your app using your IP and port. We’ll now set up a firewall and configure NGINX as a reverse proxy so we can access it directly on port 80 (HTTP).
sudo ufw enable sudo ufw status sudo ufw allow ssh sudo ufw allow http sudo ufw allow https
sudo apt install nginx sudo nano /etc/nginx/sites-available/default
In the location part of the server block, add the following:
server { listen 80; # Listen on port 80 listen [::]:80; # Listen on port 80 for IPv6 server_name yourdomain.com www.yourdomain.com; location / { proxy_pass http://localhost:3000; # replace with your app's port proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
# Check NGINX config sudo nginx -t # Restart NGINX sudo service nginx restart
You should now be able to visit your IP address with no port (port 80) and see your app. Now let's add a domain.
Follow these steps to point your Namecheap domain to your Vultr server using A records:
To check if your domain is set up correctly, run the following command in your terminal or command prompt:
ping yourdomain.com
Replace yourdomain.com
with your actual domain. If you see your server's IP address in the response, your setup is successful!
sudo apt-get update sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com # Test renewal process with certbot renew --dry-run
Now visit https://yourdomain.com and you should see your Node.js app with SSL enabled!