I deployed an application in Azure Kubernetes. I was trying to access the application through the Ingress Nginx controller. The Ingress is pointing to xxx.xxx.com and the app is deployed in the path "/react". So when I accessed the application I am able to see the title but I see the following the console GET https://dns/static/css/main.c0f79ebd.css net::ERR_ABORTED 404. I was able to access the CSS files when I accessed it through https://dns/react/static/css/main.c0f79ebd.css . So how can I add /react to the generated files path?
Following is the dockerfile content
# build environment
FROM node:12.2.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent
COPY . /app
RUN npm run build
# production environment
FROM nginx:1.16.0-alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Ingress Deployment
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
namespace: sample-ns
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
tls:
- hosts:
- dns
secretName: tls
rules:
- http:
paths:
- backend:
serviceName: my-react-app
servicePort: 80
path: /react(/|$)(.*)
If you're using Create React App, you might need to update the 'homepage' setting to reflect that the files will be served from a subdirectory rather the site root.
Putting "homepage": "https://dns/react"
in your package.json and rebuilding react/docker and redeploying might do the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.