Skip to content

Instantly share code, notes, and snippets.

@botic
Created September 15, 2019 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save botic/6362f475801e7faded6a4f72fccbc65a to your computer and use it in GitHub Desktop.
Save botic/6362f475801e7faded6a4f72fccbc65a to your computer and use it in GitHub Desktop.
SharedMobility.ai Web API Installation Guide
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName api.sharedmobility.ai
ServerAdmin webmaster@sharedmobility.ai
DocumentRoot /var/www/api.sharedmobility.ai/
<Directory /var/www/api.sharedmobility.ai/>
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error-api.sharedmobility.ai.log
CustomLog ${APACHE_LOG_DIR}/access-api.sharedmobility.ai.log combined
RewriteEngine on
ProxyPass /.well-known/ !
ProxyPass / http://127.0.0.1:54321/
ProxyPassReverse / http://127.0.0.1:54321/
ProxyPreserveHost On
SSLCertificateFile /etc/letsencrypt/live/api.sharedmobility.ai/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/api.sharedmobility.ai/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<VirtualHost *:80>
ServerName api.sharedmobility.ai
ServerAdmin webmaster@sharedmobility.ai
DocumentRoot /var/www/api.sharedmobility.ai/
<Directory /var/www/api.sharedmobility.ai/>
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error-api.sharedmobility.ai.log
CustomLog ${APACHE_LOG_DIR}/access-api.sharedmobility.ai.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.sharedmobility.ai
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
{
"apps": [
{
"name": "sharedmobility-web-api",
"cwd": "/usr/local/node-apps/sharedmobility-ai/web-api/",
"script": "./bin/www",
"error_file": "/var/log/node/error.log",
"out_file": "/var/log/node/out.log",
"max_restarts": 30,
"restart_delay": 2000,
"instances": 1,
"env": {
"NODE_ENV": "production",
"PORT": "54321"
}
}
]
}
#!/bin/bash
# First update all packages
sudo apt-get update
sudo apt-get upgrade
# Install Apache Webserver (reverse proxy for node) and enable HTTP2
sudo apt-get install apache2
sudo a2enmod http2
sudo a2enmod proxy
sudo a2enmod proxy_http
# Create the vhost
sudo pico /etc/apache2/sites-available/100-api.sharedmobility.ai.conf
sudo mkdir /var/www/api.sharedmobility.ai
# Add the following two lines to the Apache config with:
#
# ServerSignature Off
# ServerTokens Prod
sudo pico -w /etc/apache2/apache2.conf
# use the config files provided in this gist and update both vhost configs:
sudo pico -w /etc/apache2/sites-enabled/100-api.sharedmobility.ai.conf
sudo pico -w /etc/apache2/sites-enabled/100-api.sharedmobility.ai-le-ssl.conf
sudo systemctl restart apache2
# Certbot for TLS/SSL certificates
sudo apt-get install certbot python-certbot-apache
# Certbot in interactive mode => you have to enter the details.
sudo certbot --apache
sudo certbot renew --dry-run
# Check if certbot is on auto-schedule
sudo systemctl list-timers
# Install Node.js 12.x LTS release line
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
# Check your Node version
node --version
# Create a separate non-root node user
sudo groupadd --gid 2000 node
sudo useradd --uid 2000 --gid node --shell /bin/bash --create-home node
# Create app directory for node applications
sudo mkdir /usr/local/node-apps/
sudo chown node /usr/local/node-apps/
sudo chgrp node /usr/local/node-apps/
sudo mkdir /var/log/node
sudo chown node /var/log/node/
sudo chgrp node /var/log/node/
# Install git
sudo apt-get install git
cd /usr/local/node-apps/
# Clone the SharedMobility.ai repository as node user
sudo su node
git clone https://github.com/botic/sharedmobility-ai.git
exit
# Install dependencies
cd /usr/local/node-apps/sharedmobility-ai/web-api/
sudo npm install --unsafe-perm=true --allow-root
sudo chown -R node node_modules/
sudo chgrp -R node node_modules/
# Install pm2 process manager
sudo npm install -g pm2
sudo pm2 startup systemd -u node --hp /home/node
# You find the apps.json in the full gist
sudo pico /etc/pm2/apps.json
sudo -u node pm2 start /etc/pm2/apps.json
sudo -u node pm2 save
# Everything should be fine.
# Try to reboot and check if everything is running after.
sudo shutdown -r +1
# To end for your session in a proper way, sign-out asap ...
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment