I have an html file running on a docker container with this url: http://localhost:80
I want to redirect this to another port like http://localhost:8080 with NGINX.
I have the following config for it:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
upstream web {
server 127.0.0.1:80;
}
server {
listen 8080;
resolver 127.0.0.11;
autoindex off;
server_name _;
server_tokens off;
location / {
proxy_pass http://web;
}
}
}
but when I go to http://localhost:8080, I get 502 bad gateway error and here is the error I get through nginx container:
[error] 22#22: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:80/", host: "localhost:8080"
This is how I start my nginx docker:
docker run --name nginx -v c:/Users/ds-nginx-conf-main:/etc/nginx -p 8080:8080 -d nginx
here is the docker compose file of web container or the pre exciting container:
version: "3.7"
services:
web:
build: ui
ports:
- 80:80
depends_on:
- api
api:
build: app
environment:
- PORT=80
ports:
- 8020:80
test:
build:
context: ./
dockerfile: ./test/Dockerfile