Skip to content

Instantly share code, notes, and snippets.

@Kasun002
Created January 8, 2024 07:58
Show Gist options
  • Save Kasun002/a1726b6439417c820394e330900311e6 to your computer and use it in GitHub Desktop.
Save Kasun002/a1726b6439417c820394e330900311e6 to your computer and use it in GitHub Desktop.
This is an example of deploying a React app's production build to an Nginx server. If you're deploying inside a cloud instance (such as AWS EC2), this method helps reduce the resources used on the server.
FROM node:18 AS build
WORKDIR /opt/{your app name}
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build --build-arg CACHEBUST=${CACHEBUST}
FROM nginx:latest
COPY --from=build /opt/{your app name}/build /usr/share/nginx/html
EXPOSE 81
COPY nginx.conf /etc/nginx/nginx.conf
CMD ["nginx", "-g", "daemon off;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment