Score:0

Nginx and Docker with static html: Proxy pass does not forward to expected route

ru flag

I want to serve static html as a service with Docker and nginx as a reverse proxy (there are also a python backend and mysql container, which I excluded here)

I have got the following docker-compose file:

version: "3.7"

  frontend:
    build: ./frontend
    container_name: frontend
    restart: always
    ports:
      - "5000:80"

  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    ports:
      - "80:80"

Dockerfile for Frontend:

FROM nginx:alpine
COPY . /usr/share/nginx/html

nginx.conf in my I do this:

server {

    listen 80;

    location /frontend {
        proxy_pass  http://frontend:5000/;
        #proxy_pass  http://frontend:5000; -> also tried this  
    }

}

Everything builds fine, but the proxy_pass does not work as expected.

Where I can reach my app:

http://localhost:5000/

Desired:

http://localhost/frontend

Error when I try to reach the latter route:

 /frontend/ HTTP/1.1", upstream: "http://172.27.0.2:3000/frontend/", host: "localhost"
nginx       | 172.27.0.1 - - [27/Jan/2022:19:11:07 +0000] "GET /frontend/ HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" "-"

What did I do wrong?

jp flag
Use frontend:80
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.