SteveLTN / https-portal

A fully automated HTTPS server powered by Nginx, Let's Encrypt and Docker.
MIT License
4.41k stars 295 forks source link

Problem with DOMAINS ( 502 error ) #324

Closed Karlos97 closed 1 year ago

Karlos97 commented 1 year ago

version: "3.1" Hello there, this problem is probably trivial for you, but I'm not quite sure if docker is caching something or not. But even if I purge everything I still have some problems. My case is similar to https://github.com/SteveLTN/https-portal/issues/168 but still not working. I've made it working for 2 basic react apps but for frontend react app and backend nodeJs app I can't. Here is my docker compose: services: https-portal: image: steveltn/https-portal:1 ports:

volumes: https-portal-data: # Recommended, to avoid re-signing when upgrading HTTPS-PORTAL

when I docker log https-portal: 2022/10/26 17:47:37 [error] 361#361: *17 connect() failed (111: Connection refused) while connecting to upstream, client: MY_IP, server: myFrontendDomain.com, request: "GET /favicon.ico HTTP/2.0", upstream: "http://dockerFrontendImageIp:3000/favicon.ico", host: "socks-market.pl", referrer: "https://myFrontendDomain.com/catalog/"

Ofc in my files I'm exposing these ports. In ufw I allowed ports: 443,80, 3000, 3001. I've no additional nginx conf. Backend is working all the time, frontend throws 502, even if I change http://frontend:3000 on http://frontend:80 or http://frontend. Results is the same, olways errors. Couple times I made it all working but after couple minutes somehow it stopped working :D Would be glad if you helped me and by the well explain what is the problem.

SteveLTN commented 1 year ago

Are frontend and backend available from outside of docker?

Karlos97 commented 1 year ago

I've checked it and: In backend docker at the end I have normal commands: ENTRYPOINT ["npm"] CMD ["run", "start:dev"] and I can acces my backend outside by link api.myFrontendDomain.com/someBackendPath In frontend I've checked if I run the same : ["npm"] CMD ["run", "start"] - it works as well, but after this I wanted to use nginx so I go with: // ..npm install, build and so on.. //

FROM nginx:alpine WORKDIR /usr/share/nginx/html

RUN rm -rf ./*

COPY --from=builder /frontend/build .

EXPOSE 3000 ENTRYPOINT ["nginx", "-g", "daemon off;"]

SteveLTN commented 1 year ago

I would start from one of them. Let's say backend first.

If you can access it from outside Docker, then you can check what port is being exposed. Note that in docker, it probably doesn't go through the ports you expose in docker-compose.yml, but rather the actual port you expose in Dockerfile.

Then I would log into the shell of HTTPS-PORTAL and try to access from there.

Karlos97 commented 1 year ago

This is funny. When I check backend I have 3001/tcp -> 3001 when I check frontend I get template parsing error: template: :1:59: executing "" at <index $conf 0>: error calling index: index of untyped nil

is it the problem I have no nginx.conf file inside frontend file? I saw here in issues that couple people had such file but I didin't think it will be needed in my case.

Also I'm not sure what do you mean byt loggin into shell of https.

both ports checked with dockers inspect documentation command: docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID

SteveLTN commented 1 year ago

I'm afraid I can't help with what's in your frontend container.

Karlos97 commented 1 year ago

There's basic react app like the one in this repo https://github.com/Karlos97/docker-compose-raspberry-server

Edit: I also check the port with command docker port $containerId Here what I get: frontend:

  3000/tcp -> 0.0.0.0:3000
  3000/tcp -> :::3000

backend:

  3001/tcp -> 0.0.0.0:3001
  3001/tcp -> :::3001

https-portal:

  443/tcp -> 0.0.0.0:443
  443/tcp -> :::443
  80/tcp -> 0.0.0.0:80
  80/tcp -> :::80
Karlos97 commented 1 year ago

I started looking around to fix frontend. I see that nginx as default is listening to port 80 so to avoid overwriting nginx(as test I've also checked overwriting this config too - also worked, I could acces webserver with port 3000)

So now in frontend.Dockerfile I do expose 80 in docker-compose I do: frontend: container_name: frontend build: context: . dockerfile: docker/frontend.Dockerfile ports:

Now I can easilly acces webserver by port 3000. But still while I'm going to myFrontendDomain.com I see 502 Bad Gateway. To avoid any mistakes I've run everywthing again. docker-compose down -v docker prune docker-compose -f docker-compose.yml up --build --remove-orphans -d Do you know why this happends?

Karlos97 commented 1 year ago

The problem was with nginx.conf, I was missing redirect so using react app thrown me an 502 gateway error because I was trying to reach an html path in SPA application.