10

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?

2
  • Your question is a bit confusing. You've got nginx proxying port 80 to port 8000 of itself, that doesn't sound right (also, if that's all you're doing it would be more efficient to use iptables). On the machine that is the proxy is there anything on port 8000? You probably want proxy_pass http://<some other ip> unless you want to do host -> proxy -> host -> app with proxy_pass http://hostip:8000
    – AD7six
    Jun 4, 2016 at 15:38
  • so it will proxy without an upstream definition, interesting.
    – Adam
    Nov 30, 2017 at 17:04

1 Answer 1

11

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .