2.9 KiB
2.9 KiB
Деплой на традиционный хостинг
Для любого хостинга с FTP/SSH доступом
Шаг 1: Локальная сборка
npm install
npm run build
Шаг 2: Загрузка файлов
После сборки появится папка dist/ - её содержимое нужно загрузить на хостинг.
Через FTP:
- Подключитесь к хостингу через FileZilla/WinSCP
- Перейдите в папку
public_htmlилиwww - Загрузите ВСЁ содержимое папки
dist/(не саму папку!)
Через SSH:
# Соберите локально
npm run build
# Загрузите через rsync
rsync -avz --delete dist/ user@your-server.ru:/var/www/html/
Шаг 3: Настройка .htaccess (для Apache)
Создайте в корне сайта файл .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# Кеширование статических файлов
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/html "access plus 0 seconds"
</IfModule>
# Сжатие
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>
Шаг 4: Настройка для Nginx
Если на сервере Nginx, добавьте в конфигурацию сайта:
server {
listen 80;
server_name your-domain.ru www.your-domain.ru;
root /var/www/html;
index index.html;
# Сжатие
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
# SPA роутинг
location / {
try_files $uri $uri/ /index.html;
}
# Кеширование статики
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
Рекомендуемые российские хостинги:
- Timeweb - от 169 ₽/мес, отличная поддержка
- Beget - от 200 ₽/мес, очень стабильный
- Reg.ru - от 120 ₽/мес, простой интерфейс
- HostiMan - от 150 ₽/мес
- SpaceWeb - от 150 ₽/мес
Все эти хостинги поддерживают Node.js и SSH доступ.