nginx: cannot set up basic proxy (connection refused)
I am trying to set up server where my web apps will be hosted. For each app the entrypoint is an nginx server, packed in docker container, with its port 80 forwarded to somewhere on the host. Server's port 80 is listened by nginx proxy server, which chooses the app corresponding to Host
request header.
Here is an nginx config of my simple, completely static app:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
App's port 80 is bound to host's port 8000.
And here's config of the proxy:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
server {
listen 80;
# not real DNS, just an example
server_name static.myserver.net;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
DNS records myserver.net
and static.myserver.net
are bound to server's IP.
But when I try to connect to static.myserver.net
, I get error 502 and proxy log entry like this:
2016/06/04 13:26:58 [error] 5#5: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 100.100.100.100, server: static.myserver.net, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "static.myserver.net"
App's nginx logs are empty.
But both myserver.net:8000
from web and 127.0.0.1:8000
from host are completely accessible. What is wrong then?
Have found the problem. Configs seem to be correct, but the proxy server was set up as a Docker container, too. Thus, address 127.0.0.1
was pointing to Docker container, not the host. proxy_pass http://real_host_ip:8000;
is working right.