1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00
This commit is contained in:
MoonTestUse1
2024-12-25 21:31:30 +06:00
parent 674ba6d254
commit b03f329da2
3 changed files with 35 additions and 26 deletions

View File

@@ -1,3 +1,5 @@
version: '3.8'
services: services:
frontend: frontend:
build: build:

View File

@@ -1,32 +1,31 @@
# Build stage
FROM node:18-alpine as build FROM node:18-alpine as build
WORKDIR /app WORKDIR /app
# Копируем только package.json и package-lock.json сначала # Install dependencies
COPY frontend/package*.json ./ COPY frontend/package*.json ./
# Устанавливаем зависимости
RUN npm install RUN npm install
# Копируем все остальные файлы фронтенда # Copy source and build
COPY frontend/ . COPY frontend/ .
# Собираем приложение
RUN npm run build RUN npm run build
# Используем nginx для раздачи статики # Production stage
FROM nginx:alpine FROM nginx:alpine
# Копируем собранные файлы из этапа сборки # Remove default nginx static assets
RUN rm -rf /usr/share/nginx/html/*
# Copy static assets from builder stage
COPY --from=build /app/dist /usr/share/nginx/html COPY --from=build /app/dist /usr/share/nginx/html
# Создаем необходимые директории для nginx # Copy nginx configuration
RUN mkdir -p /var/cache/nginx \ COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
/var/cache/nginx/client_temp \
/var/cache/nginx/proxy_temp \ # Ensure correct permissions
/var/cache/nginx/fastcgi_temp \ RUN chown -R nginx:nginx /usr/share/nginx/html && \
/var/cache/nginx/uwsgi_temp \ chmod -R 755 /usr/share/nginx/html
/var/cache/nginx/scgi_temp
EXPOSE 80 EXPOSE 80

View File

@@ -1,28 +1,36 @@
server { server {
listen 80; listen 80 default_server;
server_name localhost; server_name _;
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html; index index.html;
# Настройка для SPA - все запросы направляются на index.html # Включаем автоиндексацию для отладки
autoindex on;
# Основной location для SPA
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html =404;
add_header Cache-Control "no-cache";
} }
# Проксирование API запросов на бэкенд # API requests
location /api/ { location /api/ {
proxy_pass http://backend:8000; proxy_pass http://backend:8000;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
# Настройка кеширования для статических файлов # Static files
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { location /assets/ {
expires max; alias /usr/share/nginx/html/assets/;
log_not_found off; expires 1y;
add_header Cache-Control "public, no-transform";
} }
} }