The goal is to:
- Return the same index.html for all requests
- Except the case when pathname starts from "/api" (e.g. localhost/api/asd) - in that case forward this request to an app running on localhost:8080
I've dealt with the task successfully just running nginx on my ubuntu. But when I try the same in docker container I get 502 for each "/api" request:
2019/11/03 14:35:39 [error] 6#6: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: 127.0.0.1, request: "GET /api/library/source/find?page=0&size=40&q=JTdCJTIycXVlcnklMjIlM0ElMjIlMjIlMkMlMjJwZXJpb2QlMjIlM0ElMjJBTlRJUVVJVFklMjIlMkMlMjJjbGFzc2lmaWNhdGlvbnMlMjIlM0ElNUIlNUQlMkMlMjJ0eXBlcyUyMiUzQSU1QiU1RCU3RA== HTTP/1.1", upstream: "http://127.0.0.1:8080/api/library/source/find?page=0&size=40&q=JTdCJTIycXVlcnklMjIlM0ElMjIlMjIlMkMlMjJwZXJpb2QlMjIlM0ElMjJBTlRJUVVJVFklMjIlMkMlMjJjbGFzc2lmaWNhdGlvbnMlMjIlM0ElNUIlNUQlMkMlMjJ0eXBlcyUyMiUzQSU1QiU1RCU3RA==", host: "localhost", referrer: "http://localhost/library/period/antiquity" 172.17.0.1 - - [03/Nov/2019:14:35:39 +0000] "GET /api/library/source/find?page=0&size=40&q=JTdCJTIycXVlcnklMjIlM0ElMjIlMjIlMkMlMjJwZXJpb2QlMjIlM0ElMjJBTlRJUVVJVFklMjIlMkMlMjJjbGFzc2lmaWNhdGlvbnMlMjIlM0ElNUIlNUQlMkMlMjJ0eXBlcyUyMiUzQSU1QiU1RCU3RA== HTTP/1.1" 502 559 "http://localhost/library/period/antiquity" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36" "-"
'172.17.0.1' looks weird. I use "nginx" image and it has the following in its /etc/hosts file:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 1a0b306a3a80
note '172.17.0.2', not '172.17.0.1'.
Dockerfile and nginx config I'm running may be found here: https://github.com/ahlinist/tempvs-ui
The image is built and run as: sudo docker build . -t tempvs-ui sudo docker run -p 80:80 tempvs-ui
What am I doing wrong? How to make the docker image send requests to localhost:8080?
http://127.0.0.1:8080/api;
, seems like your8080
container is down – Adiii