cd ~/web/
- Склонировать проект
git clone <project_link>
- Переходим в папку проекта
cd <project_name>
- Устанавливаем зависимости
yarn
- Собираем проект
yarn build
- В папке проекта должен находится
ecosystem.config.js
если его нет то необходимо создать его, содержимое должно быть таким:
module.exports = {
apps: [
{
name: '<project_name>_<port>',
exec_mode: 'cluster',
instances: 'max',
script: './node_modules/nuxt/bin/nuxt.js',
args: 'start',
env: {
NODE_ENV: 'production',
PORT: <port>
}
}
]
}
project_name
- название проекта
port
- любое число 4300 - 4399, должен быть уникальным для каждого проекта
Чтобы убедиться что порт свободен вводим команду pm2 list
Пример вывода команды ниже, из него видно что порты 4300 и 4301 уже заняты (столбец name)
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼───────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 2 │ new.francesco.ru_4301 │ default │ 2.15.3 │ cluster │ 121487 │ 25m │ 343 │ online │ 0% │ 82.4mb │ admin │ disabled │
│ 3 │ new.francesco.ru_4301 │ default │ 2.15.3 │ cluster │ 121502 │ 25m │ 336 │ online │ 0% │ 79.9mb │ admin │ disabled │
│ 0 │ new.shoes-bags.ru_4300 │ default │ 2.14.12 │ cluster │ 121467 │ 25m │ 1065 │ online │ 0% │ 95.1mb │ admin │ disabled │
│ 1 │ new.shoes-bags.ru_4300 │ default │ 2.14.12 │ cluster │ 121473 │ 25m │ 1068 │ online │ 0% │ 102.2mb │ admin │ disabled │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
- Запускаем приложение
pm2 start ecosystem.config.js
- Обновляем список процессов pm2
pm2 save
- Создаем конфиг nginx
nano /etc/nginx/sites-available/<project_name>.conf
Содержимое конфига:
map $sent_http_content_type $expires {
"text/html" epoch;
"text/html; charset=utf-8" epoch;
default off;
}
server {
listen 80; # the port nginx is listening on
server_name <project_domain>; # setup your domain here
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location / {
expires $expires;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://127.0.0.1:<port>; # set the address of the Node.js instance here
}
}
project_domain
- Домен приложения
port
- Порт который указан в ecosystem.config.js
- Активируем созданный конфиг
sudo ln -s /etc/nginx/sites-available/<project_name>.conf /etc/nginx/sites-enabled/<project_name>.conf
- Деплоим HTTPS
sudo certbot --nginx -d <project_domain>
project_domain
- Домен приложения
11.1. Если сертификаты были получены успешно то будет выдан запрос на создание редиректа на онли HTTPS, нажимаем 2 если нужен редирект
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):