Created
January 6, 2024 19:00
-
-
Save brownhash/3889b90d6d5c2e234af77bdbd820b1fc to your computer and use it in GitHub Desktop.
Configure Nginx for React application in Docker to prevent 404 on any route other than /
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Builder | |
FROM node:18-alpine3.17 as builder | |
WORKDIR /app | |
COPY . /app | |
WORKDIR /app/application_name | |
RUN npm install | |
RUN npm run build | |
# Executor | |
FROM nginx:alpine | |
# copy built package from builder image | |
COPY --from=builder /app/application_name/dist /usr/share/nginx/html | |
# copy nginx config and replace the default config with it | |
COPY ./nginx.conf /etc/nginx/conf.d/default.conf | |
EXPOSE 80 | |
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
location / { | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
try_files $uri $uri/ /index.html =404; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment