0

I am trying to dockerizing a angular universal app using nginx, and it's giving me really hard time. It keeps saying 502 bad gateway and I am unable to wrap my head around it.

This is my Dockerfile

FROM node:14-alpine AS builder
WORKDIR /app
COPY . .
RUN npm i && npm run build:ssr
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist/front-end-kevi .
ENTRYPOINT ["nginx", "-g", "daemon off;"]

In my server.ts file, I am starting the app on port 4000. So I am starting the docker image using this command

docker run -d -p 4000:80 kevin

for the reference, here is my nginx conf file.

server {
listen       80;
server_name  localhost;

root   /usr/share/nginx/html;
index  index.html index.htm;

location ~* \.(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}

location / {
    proxy_pass http://localhost:4000;
    try_files $uri $uri/ =404;
}

location /OrderMationApi/api/v3/ {
    proxy_pass http://102.133.225.222;
}}

and I am getting this error in error logs

7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "localhost:4000"

Any idea where I am doing wrong? Any help is highly appreciated. Thanks in advance.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.