defualt.conf - nginx 설정파일

server {

  listen 80;
  listen [::]:80;

  root /usr/share/nginx/html;

  index index.html;

  server_name vue-router.example.com;

  location / {
    try_files $uri $uri/ @rewrites;
  }

  location @rewrites {
    rewrite ^(.+)$ /index.html last;
  }

  location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    expires max;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  }

}

Dockerfile - docker build 파일

#Docker file for VueJS using NGINX

\# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package\*.json ./
RUN npm install
COPY . .
RUN npm run build

\# production stage
FROM nginx:stable-alpine as production-stage
COPY \--from\=build-stage /app/dist /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY \--from\=build-stage /app/default.conf /etc/nginx/conf.d/
EXPOSE 80
CMD \["nginx", "-g", "daemon off;"\]

docker build -t vuejs .
docker run --name vuejs_server -d -p 80:80 vuejs

+ Recent posts