I'm currently trying to configured nginx within a docker container to redirect to localhost:3000
when I navigate to localhost:8080
. From reading the documentation it seems I need to map the ports to redirect requests to port 80 in the container. However, when I build an image based on the following Dockerfile:
FROM alpine
RUN apk --no-cache add nginx
COPY ./nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /run/nginx
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
and run the container mapping the port 8080 to port 80 with the following command:
docker run -p 8080:80 nginx-server
When I navigate to localhost:8080
I'm not being redirected to localhost:3000 and I get
localhost didn’t send any data.
After doing some digging it seems I need to change my nginx configuration to point to proxy_pass http://host.docker.internal.However, this did not work and when I make a request to localhost:8080 I get nothing. here is my nginx configuration:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 127.0.0.1;
server_name localhost;
location / {
proxy_pass http://host.docker.internal:3000;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
Any idea what am I doing wrong?