I am having difficulty on port forwarding using Nginx reverse proxy (docker container) to an angularjs docker containers. Here is my Dockerfile and Nginx configuration with the commands I am using.
Dockerfile:
FROM nginx:latest
COPY nginx-reverseproxy.conf /etc/nginx/conf.d/
RUN mkdir /etc/nginx/ssl
COPY chained.crt /etc/nginx/ssl
COPY private.key /etc/nginx/ssl
RUN chown -R root:root /etc/nginx/ssl
RUN chmod -R 644 /etc/nginx/ssl
EXPOSE 80
EXPOSE 443
Nginx Configuration:
server {
listen 80;
listen 443 ssl;
server_name mywebserver.com;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
ssl on;
ssl_certificate /etc/nginx/ssl/chained.crt
ssl_certificate_key /etc/nginx/ssl/private.key
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:4200;
proxy_read_timeout 180;
proxy_redirect off;
proxy_redirect http://127.0.0.1:4200 $scheme://mywebserver.com;
proxy_http_version 1.1;
proxy_request_buffering off;
}
}
Command to create Nginx container:
docker run -d -p 80:80 -p 443:443 --name "container-nginx" nginx-reverse-proxy-image:latest
Command to create myserver.com container:
docker run -d -p 4200:4200 --name "container-mywebserver" angularjs-image:latest ng serve --host 0.0.0.0 --disable-host-header
I am getting "502 Bad Gateway" error message when I browse. But, when I curl localhost:4200, I could see the content. Any help would be appreciated.
nginxserver so 127.0.0.1 or 0.0.0.0 will not work. You should set up a docker-compose with depends on or setup a docker network they are both on