ssh [email protected]
apt-get update
apt-get upgrade
adduser robby
adduser robby sudo
ufw app list
ufw allow OpenSSH
ufw enable
ufw status
cd /home/robby
mkdir .ssh
nano .ssh/authorized_keys
Then past in your public ssh key.
ssh [email protected]
cd /tmp
wget https://go.dev/dl/go1.19.linux-amd64.tar.gz
tar -xvf go1.11.linux-amd64.tar.gz
sudo mv go /usr/local
nano ~/.profile
Then add the following line.
export PATH=$PATH:/usr/local/go/bin
sudo apt-get install postgresql postgresql-contrib
sudo -i -u postgres
createdb notes
createuser --interactive
psql
ALTER USER robby WITH PASSWORD 'rk';
GRANT ALL PRIVILEGES ON DATABASE notes TO robby;
\q
rsync -a ./notes [email protected]:/home/robby/go/src --exclude .env
cd /go/src/notes
go build
sudo nano /lib/systemd/system/notes.service
Add the service code below.
[Unit]
Description=notes
[Service]
Environment=PORT=3000
Environment=GO_ENV=production
Environment=GIN_MODE=release
Environment=DB_URL=postgresql://robby:[email protected]:5432/notes
Type=simple
Restart=always
RestartSec=5s
ExecStart=/home/robby/go/src/notes/notes
[Install]
WantedBy=multi-user.target
sudo service notes start
sudo service notes statusy
sudo apt install nginx
sudo ufw app list
sudo ufw allow "Nginx Full"
sudo ufw reload
sudo ufw status
cd /etc/nginx/sites-available
sudo nano notes
Add a server block like below.
server {
server_name your_domain www.your_domain;
location / {
proxy_pass http://localhost:3000;
}
}
server {
listen 80;
listen [::]:80;
location / {
proxy_pass http://localhost:3000;
}
}
sudo ln -s /etc/nginx/sites-available/notes.com /etc/nginx/sites-enabled/notes.com
sudo nginx -s reload