- Ubuntu 20.04
- HTTP
- nginx 1.20.1
- SSL
- snapd 2.51.4
- certbot 1.18.0
- Project
- Node JS LTS 14.17.6
sudo apt-get update
- Check Ubuntu updatessudo apt install nginx
- Install nginxsudo systemctl start
- Start nginxsudo systemctl enable nginx
- Start nginx with server (Auto launch)- Done
- Move to
/etc/nginx/sites-available/
- Create
%hostname%-ru.conf
- In file type:
server {
listen 80;
server_name %hostname%.ru www.%hostname%.ru;
root /var/www/%hostname%.ru/public_html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
- In command line type:
ln -s /etc/nginx/sites-available/%hostname%-ru.conf /etc/nginx/sites-enabled/
to create link between sites-available and sites-enabled - Delete default file from
/etc/nginx/sites-enabled/
(rm -rf /etc/nginx/sites-enabled/default
) - Type
nginx -t
To check syntax. Result should be:nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
- Move to
/var/www/
- Create new directory
mkdir /var/www/%hostname%/
- Create directory
mkdir /var/www/%hostname%/public_html
- In new directory place project build
- In command line type:
sudo systemctl restart nginx
to restart nginx - Done. Your project build on server
sudo apt install snapd
to install snapd (Using for certbot)sudo snap install core; sudo snap refresh core
Install and update snap coresudo apt-get remove certbot
,sudo dnf remove certbot
, orsudo yum remove certbot
sudo snap install --classic certbot
Install certbotsudo ln -s /snap/bin/certbot /usr/bin/certbot
Execute the following instruction on the command line on the machine to ensure that the certbot command can be run.sudo certbot --nginx
Install ssl in all configurationssudo certbot renew --dry-run
To authomaticaly renew certificates- Done. Go to https://%hostname%.ru
P.S To set certs for new nginx configuration type sudo certbot --nginx
- Clear folder for your project from git
rm -r /var/www/%hostname%/public_html/
- Cd to folder: ``` /var/www/%hostname%/
- Clone git repo
git clone https://github.com/%user name%/%repository name% public_html
- Cd to public_html
cd public_html
- Done
- Check updates
sudo apt update
- Install node js
sudo apt install nodejs
- Install npm
sudo apt install npm
- Install npm into your project
npm install
- Build latest version of your project
npm run build
- Edit
/etc/nginx/sites-available/%hostname%-ru.conf
root /var/www/%hostname%/public_html;
Change to
root /var/www/%hostname%/public_html/build;
- Check nginx syntax
nginx -t
- Restart nginx
sudo systemctl resart nginx
- Done
P.S. To further get updates from git in /var/www/%hostname%/public_html
type git pull
and then npm install
, npm run build