Skip to content

Instantly share code, notes, and snippets.

@kardysm
Last active September 4, 2021 16:12
Show Gist options
  • Save kardysm/8d496479dc2929721fd8641b41facb7f to your computer and use it in GitHub Desktop.
Save kardysm/8d496479dc2929721fd8641b41facb7f to your computer and use it in GitHub Desktop.
Setup n8n on mydevil hosting for custom domain (proxying)
#!/bin/sh
# Michał Kardyś (@kardysm), 2021
# script accepts:
# arg: $1 - proxy domain to external
# env: N8N_USER - username for basic auth
# env: N8N_PASSWORD - password for basic auth
#
# prerequisites:
# - DNS domain pointed correctly - for proxy address
#
# result:
# 1. n8n running on https://localhost:5678
# 2. n8n app should be accessible from PROXY_DOMAIN
# 3. credentials for n8n are set under N8N_USER and N8N_PASSWORD
# 4. runner script is available under ~/scripts/run_n8n.sh
#
# this solution is for mydevil.net shared hosting (as docker is not working here)
# http://www.mydevil.net/pp/5T6311857F
# link to mydevil with reflink (for you - it means 20% off on first order),
# if you don't want me to be referrer, remove /pp/5T6311857F
PROXY_DOMAIN=$1
# Setup node15
mkdir -p ~/bin \
&& ln -fs /usr/local/bin/node15 ~/bin/node \
&& ln -fs /usr/local/bin/npm15 ~/bin/npm \
&& source $HOME/.bash_profile
# install n8n and forever globally
npm install -g n8n forever
# install minica
cd ~/
git clone https://github.com/jsha/minica.git
go build
# setup CA
SSL_DIR='ssl/'
LOCALHOST='localhost'
LOCALHOST_PEM=~/$SSL_DIR/LOCALHOST
cd ~/
minica --domains $LOCALHOST
mkdir -p $SSL_DIR
mv $LOCALHOST $SSL_DIR
mv minica-* $SSL_DIR
# setup proxy, localhost:5678 is default config for n8n, https to proxy domain properly
devil www add $PROXY_DOMAIN proxy https://localhost 5678
# add runner script
RUNNER_NAME=run_n8n.sh
SCRIPTS_DIR=scripts
cd ~/
mkdir -p $SCRIPTS_DIR && cd $SCRIPTS_DIR
echo '#!/bin/sh
USER=$N8N_USER
PASSWORD=$N8N_PASSWORD
N8N_PROTOCOL=https \
N8N_SSL_KEY=$(echo $LOCALHOST_PEM/key.pem) \
N8N_SSL_CERT=$(echo $LOCALHOST_PEM/cert.pem) \
N8N_BASIC_AUTH_ACTIVE=true \
N8N_BASIC_AUTH_USER=$USER \
N8N_BASIC_AUTH_PASSWORD=$PASSWORD \
forever start \
$(which n8n)' \
> ./$RUNNER_NAME
chmod +x $RUNNER_NAME
./$RUNNER_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment