It loads my main page – localhost:{port}/
And if I try to go to other endpoints, it gives me a 404 error or doesn’t show it at all.
I need to configure SPA pages somehow, but I have no idea how to do it.
I have two fronts.. But they don’t display endpoints other than main
events {}
http {
server {
listen 80;
server_name localhost;
location /static/ {
alias /usr/share/nginx/html/static/;
}
location /api/ {
proxy_pass http://backend:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /admin/ {
proxy_pass http://admin:3001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://frontend:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Frontend / Main
FROM node:18-alpine AS build
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm install
RUN npm i sass react-router-dom bootstrap animate.css axios
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Admin / Panel
FROM node:18-alpine AS build
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm install
RUN npm i sass react-router-dom bootstrap animate.css axios
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Errors
frontend | 2024/05/31 15:02:44 [error] 22#22: *1 open() "/usr/share/nginx/html/brands" failed (2: No such file or directory), client: 192.168.32.1, server: localhost, request: "GET /brands HTTP/1.1", host: "localhost:3000"
frontend | 192.168.32.1 - - [31/May/2024:15:02:44 +0000] "GET /brands HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36" "-"
I’m using front > BrowserRouter
I’m sure the problem is in the configuration itself
New contributor
Desside Programming is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.