'Nginx Reverse Proxy Failure in Docker Container
I am new to Docker and nginx and am in the process of setting up a reverse proxy with nginx for my react web application. I am using Docker to contain the application, and I have another Docker container for the proxy. Both have separate nginx.conf files.
I have reached the point where my proxy request returns a 502 - Bad Gateway, and am not sure why the proxy is not forwarding to my web application. Thanks for any help in advance. Anything is appreciated.
Update: The specific error message coming from the log is: connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.192.1, server: 127.0.0.1, request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3001/”, host: “localhost:3002” ^ The problem with that error message is that http://127.0.0.1:3001/ takes me straight to my web application. Therefore, it does not make sense for the connection to be refused since something is running on that port.
Proxy conf:
upstream my_project {
server 127.0.0.1:3001 weight=3 max_fails=0;
}
server {
listen 3002;
server_name 127.0.0.1;
location / {
proxy_pass http://my_project/;
proxy_redirect default;
}
location /favicon.ico {
log_not_found off;
}
}
Application conf:
server {
listen 3001;
listen [::]:3001;
server_name localhost;
gzip on;
gzip_types text/plain text/html application/xml application/javascript;
gzip_min_length 1000;
root /usr/share/html;
location / {
root /usr/share/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
