update Dockerfile and settings for static files handling; adjust nginx config for Django and Vue integration

This commit is contained in:
2025-11-29 22:49:25 +01:00
parent 6144c28855
commit 598b10b574
5 changed files with 35 additions and 25 deletions

View File

@@ -42,11 +42,14 @@ COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Copy application code with ownership
COPY --chown=appuser:appuser . .
# Collect static files
RUN python manage.py collectstatic --noinput
# Switch to non-root user
USER appuser
# Expose Django port
EXPOSE 7080
EXPOSE 7090
# Run Django with uvicorn
CMD ["uvicorn", "MPM:application", "--host", "0.0.0.0", "--port", "7080"]
CMD ["uvicorn", "MPM:application", "--host", "0.0.0.0", "--port", "7090"]

View File

@@ -122,6 +122,11 @@ USE_TZ = True
# https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / "staticfiles"
# Proxy settings
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

View File

@@ -2,10 +2,12 @@ services:
backend:
container_name: mayo-production-manager-backend
build:
context: ./backend
context: ./backand
dockerfile: Dockerfile
environment:
NODE_ENV: production
env_file:
- ./backand/.env
volumes:
- static_content:/app/staticfiles
ports:
- 7090:7090
restart: unless-stopped
@@ -17,6 +19,11 @@ services:
dockerfile: Dockerfile
environment:
NODE_ENV: production
volumes:
- static_content:/static_django
ports:
- 7080:7080
restart: unless-stopped
volumes:
static_content:

View File

@@ -30,41 +30,35 @@ http {
listen 7080;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Serwowanie statycznych plików Django Admina
location /mayo-manager/static/ {
alias /static_django/;
}
# Serwowanie aplikacji Vue
location /mayo-manager/ {
try_files $uri $uri/ /index.html;
alias /usr/share/nginx/html/;
try_files $uri $uri/ /mayo-manager/index.html;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|map)$ {
expires 1y;
access_log off;
add_header Cache-Control "public, immutable";
add_header X-Content-Type-Options nosniff;
}
# location /assets/ {
# expires 1y;
# add_header Cache-Control "public, immutable";
# add_header X-Content-Type-Options nosniff;
# }
# BACKEND API
# Proxy do API Django
location /mayo-manager/api/ {
proxy_pass http://mayo-production-manager-backend:7090/;
proxy_pass http://mayo-production-manager-backend:7090/api/;
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;
}
# DJANGO ADMIN
# Proxy do panelu admina Django
location /mayo-manager/admin/ {
proxy_pass http://mayo-production-manager-backend:7090/admin/;
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;
}
error_page 404 /index.html;
error_page 404 /mayo-manager/index.html;
}
}

View File

@@ -6,6 +6,7 @@ import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
base: '/mayo-manager/',
plugins: [
vue(),
vueDevTools(),