From d8eb08a5f177488e2e28ec032290fb70dcc875c6 Mon Sep 17 00:00:00 2001 From: tuanvu Date: Thu, 12 Feb 2026 12:23:47 +0100 Subject: [PATCH] error with etherpad --- dockercompose/docker-compose.yml | 3 ++ dockerfiles/front/Dockerfile | 2 +- dockerfiles/front/nginx.conf | 25 ++++++--- dockerfiles/nginx/Dockerfile | 2 +- nginx.conf | 90 +++++++++++++++++++++++++------- nginxFront.conf | 20 +++++++ 6 files changed, 114 insertions(+), 28 deletions(-) create mode 100644 nginxFront.conf diff --git a/dockercompose/docker-compose.yml b/dockercompose/docker-compose.yml index abef9a0..a82e7fd 100644 --- a/dockercompose/docker-compose.yml +++ b/dockercompose/docker-compose.yml @@ -9,6 +9,7 @@ services: - db - etherpad - back + - front networks: - app-network @@ -24,6 +25,8 @@ services: - ../doodlestudent/front:/app environment: - FLASK_ENV=development + depends_on: + - back networks: - app-network diff --git a/dockerfiles/front/Dockerfile b/dockerfiles/front/Dockerfile index 3b321f0..6fcaa21 100644 --- a/dockerfiles/front/Dockerfile +++ b/dockerfiles/front/Dockerfile @@ -13,7 +13,7 @@ RUN npx ng build FROM nginx:alpine COPY --from=build /app/dist/tlcfront /usr/share/nginx/html -COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY nginxFront.conf /etc/nginx/conf.d/default.conf EXPOSE 80 diff --git a/dockerfiles/front/nginx.conf b/dockerfiles/front/nginx.conf index d152c82..f599a1e 100644 --- a/dockerfiles/front/nginx.conf +++ b/dockerfiles/front/nginx.conf @@ -1,16 +1,29 @@ server { - location /api/polls { - proxy_pass http://back:8080; - proxy_set_header Host $http_host; + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Proxy /api and all subpaths to backend service (back container on port 8080) + location /api/ { + proxy_pass http://back:8080/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; + proxy_http_version 1.1; + proxy_set_header Connection ""; } + # Also handle /api without trailing slash + location = /api { + proxy_pass http://back:8080/api; + } + + # SPA fallback for client-side routing location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html?$args; + try_files $uri $uri/ /index.html; } error_page 500 502 503 504 /50x.html; diff --git a/dockerfiles/nginx/Dockerfile b/dockerfiles/nginx/Dockerfile index 3ddb6a3..e6c472b 100644 --- a/dockerfiles/nginx/Dockerfile +++ b/dockerfiles/nginx/Dockerfile @@ -1,6 +1,6 @@ FROM nginx:latest -COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY nginxFront.conf /etc/nginx/conf.d/default.conf COPY index.html /usr/share/nginx/html/ diff --git a/nginx.conf b/nginx.conf index 26c04f6..dc4c1b1 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,5 +1,28 @@ +upstream front{ + server front:5000; +} + +upstream back{ + server back:8080; +} + +upstream etherpad{ + server etherpad:9001; +} + +upstream db{ + server db:3306; +} + +upstream smtp{ + server smtp:25; +} +########################## +## FRONTEND + API +########################## server { listen 80; + listen [::]:80; server_name _; root /usr/share/nginx/html; @@ -8,7 +31,7 @@ server { ########################## # Proxy API requests to the back service ########################## - location /api/ { + location /api/polls { proxy_pass http://back:8080/; proxy_http_version 1.1; proxy_set_header Host $host; @@ -17,28 +40,55 @@ server { proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Connection ""; } - location /web/ { - proxy_pass http://front:5080/; - proxy_http_version 1.1; - 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_set_header Connection ""; - } - location /pad/ { - proxy_pass http://etherpad:9001/; - proxy_http_version 1.1; - 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_set_header Connection ""; - } ########################## # FrontEnd returns ########################## location / { - try_files $uri $uri/ /index.html; + proxy_pass http://front:5080; + proxy_http_version 1.1; + 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_set_header Connection ""; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} + +## +## BACKEND +## +server { + listen 80; + listen [::]:80; + server_name _; + + location / { + proxy_pass http://back:8080; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + } +} + +## +## ETHERPAD +## +server { + listen 80; + listen [::]:80; + server_name _; + + location / { + proxy_pass http://etherpad:9001; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; } } diff --git a/nginxFront.conf b/nginxFront.conf new file mode 100644 index 0000000..d152c82 --- /dev/null +++ b/nginxFront.conf @@ -0,0 +1,20 @@ +server { + location /api/polls { + proxy_pass http://back:8080; + proxy_set_header Host $http_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; + } + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html?$args; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file