Nginx isn’t listening to angular http requests, the containers are running and I’m able to access the web page without getting any data from the server, please take a look at the docker files along with the nginx.conf files. Thanks in advance.
Angular docker file:
FROM node:18.13.0-alpine As build
ENV NODE_ENV=production
WORKDIR /usr/src/app
#COPY ["package.json", "package-lock.json*", "./"]
RUN npm cache clean --force
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm install -g @angular/[email protected]
RUN npm run build
#CMD ["npm", "run", "start"]
FROM nginx:latest
RUN rm -rf /usr/share/nginx/html/*
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/app/dist/Online-Store/ /usr/share/nginx/html
EXPOSE 4200
Angular nginx.conf:
server {
listen 4200;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
}
Nginx docker file:
FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
#CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
Nginx.conf
upstream online-store {
server 127.0.0.1:4200;
}
upstream backend {
server 127.0.0.1:8090;
}
server{
listen 80;
server_name _;
#root /usr/share/nginx/html;
#index index.html;
location / {
#try_files $uri /index.html
proxy_pass http://online-store/;
}
location /sockjs-node {
proxy_pass http://online-store/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /api/ {
#try_files $uri /index.html
#rewrite /api/(.*) /$1 break;
proxy_pass http://backend/;
}
}
Node docker file
FROM node:18.13.0-alpine As build
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm i
COPY . .
EXPOSE 8090
USER node
CMD ["npm", "run", "dev"]
Docker compose
version: '3.4'
services:
online-store:
container_name: online-store
image: online-store
build:
context: ./online-store
dockerfile: ./Dockerfile
environment:
NODE_ENV: production
ports:
- 4200:4200
nginx:
container_name: nginx
image: nginx
depends_on:
- backend
- online-store
restart: always
build:
dockerfile: Dockerfile
context: ./nginx
ports:
- 81:80
backend:
container_name: backend
image: backend
build:
dockerfile: Dockerfile
context: ./backend
volumes:
- /app/node_modules
- ./backend:/app
ports:
- "8090:8090"
New contributor
Mido Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.