I am trying to serve my webpack bundled app and files from a context path. Nginx Config file is as below:
nginx.conf
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /mfeexample/index.html;
}
location /mfeexample/ {
try_files $uri $uri/ /mfeexample/index.html;
}
}
Dockerfile
# Build Environment
FROM node:14.2.0-alpine as build
# Working Directory
WORKDIR /app
#Copying node package files to working directory
COPY package.* .
#Installing app dependency
RUN npm install --silent
#Copy all the code
COPY . .
#RUN Production build
RUN npm run build
# production environment
FROM nginx:stable-alpine
# Deploy the built application to Nginx server
# /usr/share/nginx/html is the Nginx static directory used to serve the appliation
COPY --from=build /app/build /usr/share/nginx/html/mfeexample
# Remove the default Nginx configuration in Nginx Container
RUN rm /etc/nginx/conf.d/default.conf
# Apply the new configuration file
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
# Expose the Application on PORT 80
EXPOSE 80
# Start Nginx server
CMD ["nginx", "-g", "daemon off;"]
Now looking at the network tab in browser, I found all the files are being served at http://localhost:3000/mfeexample/, that is exactly what I wanted. However, when I try nested route it breaks, nested route I mean http://localhost:3000/mfeexample/customer/, looking at the network tab again, nginx is looking for files under http://localhost:3000/mfeexample/customer/index.html, but I want nginx to always find the files from http://localhost:3000/mfeexample.
PS: Please keep in mind I am new to nginx and I have been doing trial and error method to get upto this point.
Thanks in advance.