How to Install Ghost/Gatsby on Debian 10

Create a new user

adduser user
usermod -aG sudo user

Install and configure Firewall

apt install -y ufw
ufw default allow outgoing
ufw default deny incoming
ufw allow ssh/tcp
ufw allow http/tcp
ufw allow https/tcp
systemctl enable ufw
ufw enable

Install Nginx

apt install nginx

Install and configure Maria DB

apt-get install mariadb-server
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

Install Node.js and Ghost-cli

apt install curl
curl -sL | sudo -E bash -
apt-get install -y nodejs
npm install ghost-cli@latest -g

Setup directories

mkdir -p /var/www/ghost
chmod 775 /var/www/ghost
chown user:user /var/www/ghost
cd /var/www/ghost 

User + install

sudo user
PATH="$PATH:/usr/sbin" ghost install 

dd an A record “www” with your vps’s ip as value

ghost config url

Generate a ssl ghost setup nginx ssl

Set again ghost config url

edit the nginx config files for your second domain to redirect to your main domain: edit both: /system/files/ and /system/files/ , replacing the content of the first location block (leave the .well-known location block - this is used for renewing certificates) with:

return 301$request_uri;

to finish run sudo nginx -t and then sudo nginx -s reload

Disable access $domain/ghost/#/signin

location ~ /ghost/ {
    rewrite ^(\/(.*\/)?ghost\/)(.*)$ $1 redirect;

Gatsby cli:

 apt install build-essential git
 npm install -g gatsby-cli

Gatsby folder

gatsby new foder-name GIT
cd foder-name
gatsby develop -H IP
gatsby build


apt install certbot certbot
certbot certonly --standalone -d $website

vi /etc/nginx/sites-enabled/$website.conf

server { 
        listen 80 default_server;
        listen [::]:80 default_server;

   root /var/www/gatsby/site/public;
   index index.html index.htm index.nginx-debian.html;
   server_name $WEBSITE www.$WEBSITE;

server {
    listen 443 ssl http2;
   server_name $WEBSITE www.$WEBSITE;

  root /var/www/gatsby/site/public;
  index index.php index.htm index.html;

  ssl_certificate  /etc/letsencrypt/live/$WEBSITE/fullchain.pem;
  ssl_certificate_key  /etc/letsencrypt/live/$WEBSITE/privkey.pem;

location / {
    alias /var/www/gatsby/site/public;
    index index.html;
#location / {
    #proxy_pass http://localhost:4000;
    #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;


npm cache clean npm cache clean --force rm -rf node_modules package-lock.json npm install npm run develop