Proxy_pass in nginx for private IP instance of EC2

I have two instances of Amazon EC2. Let me call them X and Y. I have nginx installed on both of them. Y resque works on the port 3000. Only X has a public IP and an example.com domain. Assume private IP Y is15.0.0.10

I want all requests to come to X. And only if the request URL matches the pattern /resque, then it should be processed by Y in localhost:3000/overview, which is the resque web interface. It looks like this can be done using proxy_pass in the nginx configuration.

So, in nginx.conf, I added the following:

location /resque {
    real_ip_header X-Forwarded-For;
    set_real_ip_from 0.0.0.0/0;
    allow all;

    proxy_pass  http://15.0.0.10:3000/overview;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

But now, when I visit http://example.com/resquefrom my web browser, it shows 502 Bad Gateway.

In /var/log/nginx/error.logon X,

2014/02/27 10:27:16 [error] 12559#0: *2588 connect() failed (111: Connection 
refused) while connecting to upstream, client: 123.201.181.82, server: _, 
request: "GET /resque HTTP/1.1", upstream: "http://15.0.0.10:3000/overview", 
host: "example.com" 

, ?

+4
1

, 0.0.0.0, , IP .

, , resque 127.0.0.1:3000 0.0.0.0:3000. , , . .

: Curl amazon EC2

+3

Source: https://habr.com/ru/post/1529193/


All Articles