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
FROM node:14.2.0-alpine as build
WORKDIR /app
COPY package.* .
RUN npm install --silent
COPY . .
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html/mfeexample
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
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.