- Launch the Terminal app.
ssh-keygen -t rsa
- Press
ENTER
to store the key in the default folder /Users/lamadev/.ssh/id_rsa). - Type a passphrase (characters will not appear in the terminal).
- Confirm your passphrase to finish SSH Keygen. You should get an output that looks something like this:
Your public key has been saved in /Users/lamadev/.ssh/id_rsa.pub.
The key fingerprint is:
ae:89:72:0b:85:da:5a:f4:7c:1f:c2:43:fd:c6:44:30 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . |
| E . |
| . . o |
| o . . S . |
| + + o . + |
|. + o = o + |
| o...o * o |
|. oo.o . |
+-----------------+
- Copy your public SSH Key to your clipboard using the following code:
pbcopy < ~/.ssh/id_rsa.pub
- Download PuTTY and PuTTYgen.
- Open up PuTTYgen and click the
Generate
. - Copy your key.
- Enter a key passphrase and confirm.
- Save the private key.
After copying the SSH Key go the to hosting service provider dashboard and paste your key and save. After,
ssh root@<server ip address>
- Open the PuTTY app.
- Enter your IP address.
- Open the following section: Connection - SSH - Auth
- Browse the folders and choose your private key.
systemctl stop apache2
systemctl disable apache2
apt remove apache2
to delete related dependencies:
apt autoremove
apt clean all && sudo apt update && sudo apt dist-upgrade
rm -rf /var/www/html
apt install nginx
apt install ufw
ufw enable
ufw allow "Nginx Full"
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default
nano /etc/nginx/sites-available/netflix
server {
listen 80;
location / {
root /var/www/netflix;
index index.html index.htm;
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;
try_files $uri $uri/ /index.html;
}
}
ln -s /etc/nginx/sites-available/netflix /etc/nginx/sites-enabled/netflix
nano /var/www/netflix/index.html
systemctl start nginx
apt install git
mkdir netflix
cd netflix
git clone <your repository>
nano /etc/nginx/sites-available/netflix
location /api {
proxy_pass http://45.90.108.107:8800;
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;
}
If you check the location /api you are going to get "502" error which is good. Our configuration works. The only thing we need to is running our app
apt install nodejs
apt install npm
cd api
npm install
nano .env
node index.js
But if you close your ssh session here. It's gonna kill this process. To prevent this we are going to need a package which is called pm2
npm i -g pm2
Let's create a new pm2 instance
pm2 start --name api index.js
pm2 startup ubuntu
pm2 start app.js --name my-api # Name process
pm2 start app.js -i 0
# Will start maximum processes with LB depending on available CPUs
pm2 start app.js -i max
# Same as above, but deprecated.
pm2 scale app +3
# Scales app
up by 3 workers
pm2 scale app 2
# Scales app
up or down to 2 workers total\
pm2 list
# Display all processes status
pm2 jlist
# Print process list in raw JSON
pm2 prettylist
# Print process list in beautified JSON
pm2 describe 0
# Display all information about a specific process
pm2 monit
# Monitor all processes\
pm2 logs [--raw]
# Display all processes logs in streaming
pm2 flush
# Empty all log files
pm2 reloadLogs
# Reload all logs\
pm2 stop all
# Stop all processes
pm2 restart all
# Restart all processes
pm2 reload all
# Will 0s downtime reload (for NETWORKED apps)
pm2 stop 0
# Stop specific process id
pm2 restart 0
# Restart specific process id
pm2 delete 0
# Will remove process from pm2 list
pm2 delete all
# Will remove all processes from pm2 list\
pm2 reset <process>
# Reset meta data (restarted time...)
pm2 updatePM2
# Update in memory pm2
pm2 ping
# Ensure pm2 daemon has been launched
pm2 sendSignal SIGUSR2 my-app
# Send system signal to script
pm2 start app.js --no-daemon
pm2 start app.js --no-vizion
pm2 start app.js --no-autorestart
cd ../client
nano .env
Paste your env file.
npm i
Let's create the build file
npm run build
Right now, we should move this build file into the main web file
rm -rf /var/www/netflix/*
mkdir /var/www/netflix/client
cp -r build/* /var/www/netflix/client
Let's make some server configuration
location / {
root /var/www/netflix/client/;
index index.html index.htm;
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;
try_files $uri $uri/ /index.html;
}
1 - Make sure that you created your A records on your domain provider website. 2 - Change your pathname from Router 3 - Change your env files and add the new API address 4 - Add the following server config
server {
listen 80;
server_name safakkocaoglu.com www.safakkocaoglu.com;
location / {
root /var/www/netflix/client;
index index.html index.htm;
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;
try_files $uri $uri/ /index.html;
}
}
server {
listen 80;
server_name api.safakkocaoglu.com;
location / {
proxy_pass http://45.90.108.107:8800;
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;
}
}
server {
listen 80;
server_name admin.safakkocaoglu.com;
location / {
root /var/www/netflix/admin;
index index.html index.htm;
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;
try_files $uri $uri/ /index.html;
}
}
apt install certbot python3-certbot-nginx
Make sure that Nginx Full rule is available
ufw status
certbot --nginx -d example.com -d www.example.com
Let’s Encrypt’s certificates are only valid for ninety days. To set a timer to validate automatically:
systemctl status certbot.timer