fix: nginx setup
This commit is contained in:
1 parent
400e0408f3
commit
40b6afd85c
5 files changed
+31
-11
No files matched your search
@@ -20,10 +20,13 @@ npm install
|
|||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Docker (nginx, http://localhost:8090):
|
Docker (nginx, http://localhost:8090/ue1):
|
||||||
```sh
|
```sh
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
|
BASE_PATH=/ docker compose up -d --build # anderer Pfad, hier direkt unter http://localhost:8090/
|
||||||
```
|
```
|
||||||
|
Der Pfad wird beim Build festgelegt (Build-Argument `BASE_PATH`, Standard `/ue1`). Der Reverse Proxy muss den Pfad
|
||||||
|
unverändert an den Container weiterreichen, also ohne das Präfix zu entfernen.
|
||||||
|
|
||||||
Die Web-Version verwendet einen anderen Zufallsgenerator als Python: Läufe mit demselben Seed sind reproduzierbar,
|
Die Web-Version verwendet einen anderen Zufallsgenerator als Python: Läufe mit demselben Seed sind reproduzierbar,
|
||||||
stimmen aber nicht mit den Python-Läufen überein.
|
stimmen aber nicht mit den Python-Läufen überein.
|
||||||
+4
-1
@@ -1,6 +1,9 @@
|
|||||||
services:
|
services:
|
||||||
web:
|
web:
|
||||||
build: ./web
|
build:
|
||||||
|
context: ./web
|
||||||
|
args:
|
||||||
|
BASE_PATH: ${BASE_PATH:-/ue1}
|
||||||
image: waldbrand-simulation
|
image: waldbrand-simulation
|
||||||
ports:
|
ports:
|
||||||
- "8090:80"
|
- "8090:80"
|
||||||
|
|||||||
+9
-2
@@ -1,10 +1,17 @@
|
|||||||
|
# Pfad, unter dem die App ausgeliefert wird, z.B. /ue1
|
||||||
|
ARG BASE_PATH=/
|
||||||
|
|
||||||
FROM node:26-trixie-slim AS build
|
FROM node:26-trixie-slim AS build
|
||||||
|
ARG BASE_PATH
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN BASE_PATH="$BASE_PATH" npm run build
|
||||||
|
|
||||||
FROM nginx:mainline-trixie
|
FROM nginx:mainline-trixie
|
||||||
|
ARG BASE_PATH
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
# Willkommensseite des Images entfernen
|
||||||
|
RUN rm -rf /usr/share/nginx/html/*
|
||||||
|
COPY --from=build /app/dist /usr/share/nginx/html/${BASE_PATH}
|
||||||
+5
-2
@@ -4,6 +4,9 @@ server {
|
|||||||
server_name _;
|
server_name _;
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
|
|
||||||
|
# Weiterleitung von /ue1 auf /ue1/ relativ, damit sie hinter einem Reverse Proxy stimmt
|
||||||
|
absolute_redirect off;
|
||||||
|
|
||||||
gzip on;
|
gzip on;
|
||||||
gzip_types text/css application/javascript image/svg+xml;
|
gzip_types text/css application/javascript image/svg+xml;
|
||||||
|
|
||||||
@@ -12,8 +15,8 @@ server {
|
|||||||
add_header Cache-Control "no-cache";
|
add_header Cache-Control "no-cache";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dateinamen in /assets enthalten einen Hash und ändern sich mit jedem Build
|
# Dateinamen in assets/ enthalten einen Hash und ändern sich mit jedem Build
|
||||||
location /assets/ {
|
location ~ /assets/ {
|
||||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+9
-5
@@ -1,8 +1,12 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig, loadEnv } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
// Relative Pfade, damit die App auch unter einem Unterpfad wie /ue1 läuft
|
// Pfad, unter dem die App ausgeliefert wird, z.B. BASE_PATH=/ue1 → https://sim.teier.net/ue1
|
||||||
base: "./",
|
// Absolut statt relativ, damit die Assets auch ohne abschließenden Schrägstrich gefunden werden
|
||||||
plugins: [react()],
|
const pfad = (loadEnv(mode, ".", "").BASE_PATH ?? "").replace(/^\/+|\/+$/g, "");
|
||||||
|
return {
|
||||||
|
base: pfad ? `/${pfad}/` : "/",
|
||||||
|
plugins: [react()],
|
||||||
|
};
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user