Docker Compose를 통해 React 앱을 배포 중nginx를 통해 하위 도메인으로 프록시 중 (DOMAIN/REACT)
404 Not Found 발생하위 URL로 접속하더라도 루트와 같은 정적 파일을 제공하도록 한다.
nginx.conf 파일 작성nginx.conf
server {
listen 80;
location /REACT/ {
alias /usr/share/nginx/html/;
try_files $uri $uri/ /index.html;
}
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
}
nginx.conf 파일 또한 컨테이너 내부에 복사Dockerfile
FROM node:22 AS build-stage
WORKDIR /app
COPY package.json package-lock.json ./
RUN yarn install
COPY . .
RUN yarn build
FROM nginx:latest
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf