From bc6c9470d5d5716e125f0420697f7c61df2f3093 Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Sat, 24 May 2025 23:30:24 +0900 Subject: [PATCH] add vhost --- Dockerfile | 14 ++++++++------ vhosts.conf | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 vhosts.conf diff --git a/Dockerfile b/Dockerfile index 8fbc672..a3d6f4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,20 +20,22 @@ COPY eslint.config.mjs ./eslint.config.mjs COPY .env.production ./.env.production COPY .prettierrc ./.prettierrc COPY index.html ./index.html +COPY vhosts.conf ./vhosts.conf RUN npm run build:production -FROM node:22-alpine +# FROM node:22-alpine # Copy node modules and build directory from base image to new image -COPY --from=base ./node_modules ./node_modules -COPY --from=base ./package.json ./package.json -COPY --from=base /dist /dist -COPY --from=base /src /src -COPY --from=base /public /public +# COPY --from=base ./node_modules ./node_modules +# COPY --from=base ./package.json ./package.json +# COPY --from=base /dist /dist +# COPY --from=base /src /src +# COPY --from=base /public /public # Expose required port FROM nginx:alpine COPY --from=base /dist /usr/share/nginx/html +COPY --from=base /vhosts.conf /etc/nginx/conf.d/default.conf CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/vhosts.conf b/vhosts.conf new file mode 100644 index 0000000..7f8f344 --- /dev/null +++ b/vhosts.conf @@ -0,0 +1,29 @@ +server { + listen 80 default_server; + server_name /usr/share/nginx/html; + + root /usr/share/nginx/html; + index index.html index.htm; + + location ~* \.(?:manifest|appcache|html?|xml|json)$ { + expires -1; + # access_log logs/static.log; # I don't usually include a static log + } + + location ~* \.(?:css|js|json)$ { + try_files $uri =404; + expires 1y; + access_log off; + add_header Cache-Control "public"; + } + + # Any route containing a file extension (e.g. /devicesfile.js) + location ~ ^.+\..+$ { + try_files $uri =404; + } + + # Any route that doesn't have a file extension (e.g. /devices) + location / { + try_files $uri $uri/ /index.html; + } +}