From a02c1a19a80d70278bf1e7f8d6493c47f19d63d3 Mon Sep 17 00:00:00 2001 From: aldbr Date: Thu, 30 Nov 2023 17:35:47 +0100 Subject: [PATCH] fix: nginx does not handle pages with no subdirectory --- Dockerfile | 5 ++++- config/nginx/default.conf | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 config/nginx/default.conf diff --git a/Dockerfile b/Dockerfile index 4fcf6992..4f5a7477 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ # Minimize the size and complexity of the final Docker image by separating the # build stage and the runtime stage into two different steps + +# Stage 1: Build the Next.js application FROM node:16-alpine AS build WORKDIR /app # Install the project dependencies @@ -10,7 +12,8 @@ COPY . . # Build the static export with telemetry disabled (https://nextjs.org/telemetry) RUN NEXT_TELEMETRY_DISABLED=1 npm run build -# Copy the website from the previous container to a Nginx container +# Stage 2: Copy the website from the previous container to a Nginx container FROM nginxinc/nginx-unprivileged:alpine EXPOSE 8080 COPY --from=build /app/out /usr/share/nginx/html +COPY ./config/nginx/default.conf /etc/nginx/conf.d/default.conf diff --git a/config/nginx/default.conf b/config/nginx/default.conf new file mode 100644 index 00000000..a98ca097 --- /dev/null +++ b/config/nginx/default.conf @@ -0,0 +1,16 @@ +server { + listen 8080; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri.html $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} +