Get a 404 Not Found from nginx when ng build Get a 404 Not Found from nginx when ng build nginx nginx

Get a 404 Not Found from nginx when ng build


Try adding this to your ngnix config file:

http {    ... other configs    location / {        try_files $uri $uri/ index.html    }}


Try this solution and I think should work because also I working with Nginx and AngularDockerfile must be:

# The builder from node imageFROM node:alpine as builder# build-time variablesRUN apk update && apk add --no-cache make git# Move our files into directory name "app"WORKDIR /yourworkdirCOPY /yourworkdir/package*.json /frontend/RUN npm installCOPY ./yourworkdir /frontend/RUN npm run build -- --output-path=./dist/outFROM nginx:alpineCOPY nginx/default.conf /etc/nginx/nginx.confCOPY --from=builder /frontend/dist/out/ /usr/share/nginx/htmlEXPOSE 80CMD ["nginx", "-g", "daemon off;"]

and for Nginx configuration

 worker_processes  1;    events {        worker_connections  1024;    }    http {        include /etc/nginx/mime.types;        client_max_body_size 100m;        server {            listen 80;            charset utf-8;            server_name  localhost;            root   /usr/share/nginx/html;            index  index.html index.htm;            include /etc/nginx/mime.types;            gzip on;            gzip_types text/css text/javascript application/x-javascript application/json;            # frontend            location / {                try_files $uri $uri/ /index.html;            }        }    }

I think it will be better if you put also your docker-compose file.


Expose a port in your Dockerfile :

### STAGE 1: Build ###FROM node:12.7-alpine AS buildWORKDIR /usr/src/appCOPY package.json ./RUN npm installCOPY . .RUN npm run build### STAGE 2: Run ###FROM nginx:1.17.1-alpineEXPOSE YOUR_PORTCOPY --from=build /usr/src/app/dist/TBH-GUI /usr/share/nginx/html

This is a basic configuration for nginx :

server {  listen YOUR_PORT;  server_name YOUR_SERVER_NAME;  location / {    root /usr/share/nginx/html;    index index.html index.htm;    try_files $uri $uri/ /index.html;  }}