Learn virtual private server.
1 Make user in UBUNTU
In, local machine create ssh keys to access the vps with ssh key
Create new public and private key
Note
Note: You can give directory location <filename>
to save private and public key.
See public key
1
| cat ~/.ssh/<filename>.pub
|
- Copy content to newly created vps, Now you can access vps without using password.
1.1 Create a new user
1
| sudo adduser <username>
|
1.2 Add user to “sudo” group
Give sudo permissions to new user
1
2
| sudo usermod -aG <username>
sudo usermod -aG sudo <username>
|
Check sudo access
1
| sudo cat /var/log/auth.log
|
2 Server Setup
Login with new user
1
| ssh <username>@IP_ADDRESS
|
Create a new directory if it doesn’t exist
Create authorized_keys file and paste public key
1
| sudo nano ~/.ssh/authorized_keys
|
Change file permissions
1
| sudo cat /var/log/auth.log
|
Disable root login, Find PermitRootLogin
and set it no
1
| sudo vi /etc/ssh/sshd_config
|
Note: Do it with new user’s access.
Restart ssh daemon
1
| sudo service sshd restart
|
Disable root login
1
| sudo vi /etc/ssh/sshd_config
|
3 Nginx setup
Install nginx
Start nginx
1
| sudo service nginx start
|
Firewall
1
| sudo ufw allow 'Nginx HTTP'
|
Check status of ngnix
Navigate to nginx
1
| cd /etc/nginx/sites-available
|
Update default
Setup Github Action
Add sudo permission for action
1
| sudo visudo -f /etc/sudoers.d/<username>
|
Put this line of script
1
| <username> ALL=(ALL) NOPASSWD: /usr/sbin/service nginx start,/usr/sbin/service nginx stop,/usr/sbin/service nginx restart
|
Reboot the system
Install node with latest version
How To Install Node.js on Ubuntu 20.04
Install npm, serve and pm2
1
2
3
4
5
6
7
8
| # Install npm
sudo npm i -g npm
# Install pm2
sudo npm i -g pm2
# Install serve
sudo npm i -g serve
|
Run server with pm2
1
2
3
4
5
| # pm2 task creation for backend
pm2 start npm --name "backend" -- run start
# pm2 task creation for react app
pm2 serve --name "admin" build <port> --spa
|
Check Status and Log
1
2
3
4
5
| # pm2 status
pm2 status
# pm2 log
pm2 log
|
nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
| ##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
# listen 80 default_server;
# listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/app/_work/<project>/<project>;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name example.com <ip_address>;
location /api/ {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
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;
}
location / {
proxy_pass http://localhost:5000;
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;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
|
If you want new configuration file for nginx, create one and write configuation
1
| sudo ln -s /etc/nginx/sites-available/<new-nginx-conf-file> /etc/nginx/sites-enabled/<new-nginx-conf-file>
|