Blog · GitLab (User) Created at 2018-1-21 19:12:25 Updated at 2018-2-14 09:19:14 Tomáš Hübelbauer
Remove in favor of Bloggo prefix

NodeJS Ubuntu VPS

Tested on: Wedos, Digital Ocean

index.mjs

import express from 'express'
const server = express()
server.use('/', (request, response) => response.send('Hello, World!'))
server.listen(80, () => console.log(`Listening on :80`))

package.json

{
  "name": "root",
  "version": "1.0.0",
  "description": "",
  "main": "index.mjs",
  "scripts": {
    "start": "node --experimental-modules index.mjs",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.2"
  }
}

run.sh

#!/usr/bin/env bash
date | tee -a run.log
while :
do
    npm start | tee -a run.log
    date | tee -a run.log
done

Custom Domain

Multiple Domains

curl -O http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
rm nginx_signing.key
nano /etc/apt/sources.list

/etc/apt/sources.list

# `codename` is distro name:
# 14.04 trusty
# 16.04 xenial
# 17.04 zesty
deb http://nginx.org/packages/ubuntu/ codename nginx
deb-src http://nginx.org/packages/ubuntu/ codename nginx
apt-get update
apt-get install nginx

/etc/nginx/conf.d/virtual.conf

server {
    listen 80;
    server_name hubelbauer.net *.hubelbauer.net;
    location / {
        #proxy_pass http://localhost:8001;
        return 200 'hubelbauer.net';
        add_header Content-Type text/plain;
    }
}

server {
    listen 80;
    server_name async-await.net *.async-await.net;
    location / {
        #proxy_pass http://localhost:8002;
        return 200 'async-await.net';
        add_header Content-Type text/plain;
    }
}

Let's Encrypt

add-apt-repository ppa:certbot/certbot
apt update
apt install python-certbot-nginx

This should be just certbot --nginx -d hubelbauer.net -d www.hubelbauer.net, but there is a security issue currently preventing it.

server {
    listen 80;
    server_name hubelbauer.net *.hubelbauer.net;
    location / {
        proxy_pass http://localhost:8001;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/hubelbauer.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/hubelbauer.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

server {
    listen 80;
    server_name async-await.net *.async-await.net;
    location / {
        proxy_pass http://localhost:8002;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/async-await.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/async-await.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}
Changes (18)
2018-2-14 09:19:14 Tomáš Hübelbauer
Remove in favor of Bloggo prefix
2018-1-26 21:16:40 Tomáš Hübelbauer
Add Yarn task
2018-1-26 08:47:57 Tomáš Hübelbauer
Add a task for Postgress
2018-1-23 21:30:19 Tomáš Hübelbauer
Add IPv6 task
2018-1-23 21:18:53 Tomáš Hübelbauer
Finalize Let's Encrypt documentation
2018-1-23 20:24:55 Tomáš Hübelbauer
Add Let's Encrypt HTTPS certificate instructors
2018-1-23 19:43:36 Tomáš Hübelbauer
Extend multiple domains per VPS documentation
2018-1-22 15:45:59 Tomáš Hübelbauer
Add NGinx installation instructions
2018-1-22 15:35:18 Tomáš Hübelbauer
Add NGinx installation link
2018-1-22 14:45:28 Tomáš Hübelbauer
Document multiple domains
2018-1-22 14:35:20 Tomáš Hübelbauer
Add custom domain section header
2018-1-22 14:34:35 Tomáš Hübelbauer
Document custom domain setup
2018-1-21 20:34:36 Tomáš Hübelbauer
Linkize the VPS IP and add todoes
2018-1-21 20:29:27 Tomáš Hübelbauer
Turn into a bloggo
2018-1-21 20:28:50 Tomáš Hübelbauer
Inform on how to kill hypervisor
2018-1-21 20:09:10 Tomáš Hübelbauer
Split to sections for VPS providers
2018-1-21 20:08:10 Tomáš Hübelbauer
Describe Wedos VPS solution
2018-1-21 19:36:22 Tomáš Hübelbauer
Add theory on how to run auto-restarting process on Ubuntu
Comments E-mail me!