I keep getting this error when I try to connect to my reverse proxy:
2022/09/20 01:06:43 [error] 25#25: *5 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: localhost, request: "GET /sdr_user HTTP/1.1", upstream: "http://127.0.0.1:59524/values", host: "localhost:9191"
2022/09/20 01:06:43 [warn] 25#25: *5 upstream server temporarily disabled while connecting to upstream, client: x.x.x.x, server: localhost, request: "GET /sdr_user HTTP/1.1", upstream: "http://127.0.0.1:59524/values", host: "localhost:9191"
2022/09/20 01:06:43 [error] 25#25: *5 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: localhost, request: "GET /sdr_user HTTP/1.1", upstream: "http://127.0.0.1:59524/values", host: "localhost:9191"
2022/09/20 01:06:43 [warn] 25#25: *5 upstream server temporarily disabled while connecting to upstream, client: x.x.x.x, server: localhost, request: "GET /sdr_user HTTP/1.1", upstream: "http://127.0.0.1:59524/values", host: "localhost:9191"
I have tried searching and it said to define my upstream server which i already have in my default.conf file like this:
upstream api_server {
server localhost:59524;
}
server {
listen 80;
server_name localhost;
location /sdr_user{
proxy_pass http://api_server/values;
}
}
My reverse proxy is located in another container separate from my other projects. However, when I directly access localhost:59524, i can access the link without any issues.
Am I missing another configuration?
CodePudding user response:
localhost
has no meaning when you work with containers.
If you have a docker-compose.yml with 2 services: nginx and the application, then your nginx sees the application by the name of the service defined in docker-compose.yml
Example:
docker-compose.yml
version: '3'
services:
svc1:
image: nginx
ports:
- "8080:80"
volumes:
- "./default.conf:/etc/nginx/conf.d/default.conf:ro"
svc2:
image: <some app>
(no need to expose ports for svc2)
Your default.conf
should look like:
upstream api_server {
server svc2:59524;
}
server {
listen 80;
server_name localhost;
location /sdr_user{
proxy_pass http://api_server/values;
}
}
(assuming your app is running on port 59524 inside the container)