M
M
Maxim Barulin2017-09-21 11:57:51
Nginx
Maxim Barulin, 2017-09-21 11:57:51

Why doesn't redirect to container from nginx work?

Good day!
There are two containers in one nginx in another redmine.
Redmine has a port open and if you access this port directly from a browser, then everything is ok.
Installed a container with nginx.
Created a config:

server {
  listen        80;
  server_name  myhost.ru  www.myhost.ru;
  error_log /etc/nginx/logs/debug.log debug;

    location /test {
    	rewrite    ^/test/?([^/]*) /$1 break;
        proxy_pass http://localhost:10083;
        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 when accessing myhost.ru/test, it turns out 502. At the same time, there is no access to it in the log of the redmine itself. What have I done wrong?
nginx log:
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Host: myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Connection: keep-alive"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Cache-Control: max-age=0"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Upgrade-Insecure-Requests: 1"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Accept-Encoding: gzip, deflate"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"
2017/09/21 08:23:53 [debug] 5#5: *1 http header: "Cookie: _ym_uid=1496406692314004448"
2017/09/21 08:23:53 [debug] 5#5: *1 http header done
2017/09/21 08:23:53 [debug] 5#5: *1 event timer del: 3: 1505982293410
2017/09/21 08:23:53 [debug] 5#5: *1 generic phase: 0
2017/09/21 08:23:53 [debug] 5#5: *1 rewrite phase: 1
2017/09/21 08:23:53 [debug] 5#5: *1 test location: "/test"
2017/09/21 08:23:53 [debug] 5#5: *1 using configuration "/test"
2017/09/21 08:23:53 [debug] 5#5: *1 http cl:-1 max:1048576
2017/09/21 08:23:53 [debug] 5#5: *1 rewrite phase: 3
2017/09/21 08:23:53 [debug] 5#5: *1 http script regex: "^/test/?([^/]*)"
2017/09/21 08:23:53 [notice] 5#5: *1 "^/test/?([^/]*)" matches "/test", client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", host: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: "/"
2017/09/21 08:23:53 [debug] 5#5: *1 http script capture: ""
2017/09/21 08:23:53 [debug] 5#5: *1 http script regex end
2017/09/21 08:23:53 [notice] 5#5: *1 rewritten data: "/", args: "", client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", host: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 post rewrite phase: 4
2017/09/21 08:23:53 [debug] 5#5: *1 generic phase: 5
2017/09/21 08:23:53 [debug] 5#5: *1 generic phase: 6
2017/09/21 08:23:53 [debug] 5#5: *1 generic phase: 7
2017/09/21 08:23:53 [debug] 5#5: *1 access phase: 8
2017/09/21 08:23:53 [debug] 5#5: *1 access phase: 9
2017/09/21 08:23:53 [debug] 5#5: *1 access phase: 10
2017/09/21 08:23:53 [debug] 5#5: *1 post access phase: 11
2017/09/21 08:23:53 [debug] 5#5: *1 generic phase: 12
2017/09/21 08:23:53 [debug] 5#5: *1 generic phase: 13
2017/09/21 08:23:53 [debug] 5#5: *1 http init upstream, client timer: 0
2017/09/21 08:23:53 [debug] 5#5: *1 epoll add event: fd:3 op:3 ev:80002005
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: "Host"
2017/09/21 08:23:53 [debug] 5#5: *1 http script var: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: "X-Real-IP"
2017/09/21 08:23:53 [debug] 5#5: *1 http script var: "10.80.2.244"
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: "X-Forwarded-For"
2017/09/21 08:23:53 [debug] 5#5: *1 http script var: "10.80.2.244"
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: "Connection"
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: "close"
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: ""
2017/09/21 08:23:53 [debug] 5#5: *1 http script copy: ""
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "Cache-Control: max-age=0"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "Upgrade-Insecure-Requests: 1"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "User-Agent: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "Accept-Encoding: gzip, deflate"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header: "Cookie: _ym_uid=1496406692314004448"
2017/09/21 08:23:53 [debug] 5#5: *1 http proxy header:
"GET / HTTP/1.0
Host: myhost.ru
X-Real-IP: 10.80.2.244
X-Forwarded-For: 10.80.2.244
Connection: close
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: _ym_uid=1496406692314004448
"
2017/09/21 08:23:53 [debug] 5#5: *1 http cleanup add: 00005584A18C8258
2017/09/21 08:23:53 [debug] 5#5: *1 get rr peer, try: 2
2017/09/21 08:23:53 [debug] 5#5: *1 get rr peer, current: 00005584A18CDAE0 -1
2017/09/21 08:23:53 [debug] 5#5: *1 stream socket 12
2017/09/21 08:23:53 [debug] 5#5: *1 epoll add connection: fd:12 ev:80002005
2017/09/21 08:23:53 [debug] 5#5: *1 connect to 127.0.0.1:10083, fd:12 #2
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream connect: -2
2017/09/21 08:23:53 [debug] 5#5: *1 posix_memalign: 00005584A18A6020:128 @16
2017/09/21 08:23:53 [debug] 5#5: *1 event timer add: 12: 60000:1505982293411
2017/09/21 08:23:53 [debug] 5#5: *1 http finalize request: -4, "/?" a:1, c:2
2017/09/21 08:23:53 [debug] 5#5: *1 http request count:2 blk:0
2017/09/21 08:23:53 [debug] 5#5: *1 http run request: "/?"
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream check client, write event:1, "/"
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream request: "/?"
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream process header
2017/09/21 08:23:53 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", upstream: "127.0.0.1:10083", host: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 http next upstream, 2
2017/09/21 08:23:53 [debug] 5#5: *1 free rr peer 2 4
2017/09/21 08:23:53 [warn] 5#5: *1 upstream server temporarily disabled while connecting to upstream, client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", upstream: "127.0.0.1:10083", host: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 free rr peer failed: 00005584A18CDAE0 0
2017/09/21 08:23:53 [debug] 5#5: *1 close http upstream connection: 12
2017/09/21 08:23:53 [debug] 5#5: *1 free: 00005584A18A6020, unused: 48
2017/09/21 08:23:53 [debug] 5#5: *1 event timer del: 12: 1505982293411
2017/09/21 08:23:53 [debug] 5#5: *1 reusable connection: 0
2017/09/21 08:23:53 [debug] 5#5: *1 get rr peer, try: 1
2017/09/21 08:23:53 [debug] 5#5: *1 get rr peer, current: 00005584A18CDC98 1
2017/09/21 08:23:53 [debug] 5#5: *1 stream socket 12
2017/09/21 08:23:53 [debug] 5#5: *1 epoll add connection: fd:12 ev:80002005
2017/09/21 08:23:53 [debug] 5#5: *1 connect to 127.0.0.1:10083, fd:12 #3
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream connect: -2
2017/09/21 08:23:53 [debug] 5#5: *1 posix_memalign: 00005584A18A6020:128 @16
2017/09/21 08:23:53 [debug] 5#5: *1 event timer add: 12: 60000:1505982293412
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream request: "/?"
2017/09/21 08:23:53 [debug] 5#5: *1 http upstream process header
2017/09/21 08:23:53 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", upstream: "127.0.0.1:10083", host: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 http next upstream, 2
2017/09/21 08:23:53 [debug] 5#5: *1 free rr peer 1 4
2017/09/21 08:23:53 [warn] 5#5: *1 upstream server temporarily disabled while connecting to upstream, client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", upstream: "127.0.0.1:10083", host: "myhost.ru"
2017/09/21 08:23:53 [debug] 5#5: *1 free rr peer failed: 00005584A18CDC98 0
2017/09/21 08:23:53 [debug] 5#5: *1 finalize http upstream request: 502
2017/09/21 08:23:53 [debug] 5#5: *1 finalize http proxy request
2017/09/21 08:23:53 [debug] 5#5: *1 close http upstream connection: 12
2017/09/21 08:23:53 [debug] 5#5: *1 free: 00005584A18A6020, unused: 48
2017/09/21 08:23:53 [debug] 5#5: *1 event timer del: 12: 1505982293412
2017/09/21 08:23:53 [debug] 5#5: *1 reusable connection: 0
2017/09/21 08:23:53 [debug] 5#5: *1 http finalize request: 502, "/?" a:1, c:1
2017/09/21 08:23:53 [debug] 5#5: *1 http special response: 502, "/?"
2017/09/21 08:23:53 [debug] 5#5: *1 HTTP/1.1 502 Bad Gateway
Server: nginx/1.13.5
Date: Thu, 21 Sep 2017 08:23:53 GMT
Content-Type: text/html
Content-Length: 575
Connection: keep-alive
2017/09/21 08:23:53 [debug] 5#5: *1 write new buf t:1 f:0 00005584A18B8240, pos 00005584A18B8240, size: 157 file: 0, size: 0
2017/09/21 08:23:53 [debug] 5#5: *1 http write filter: l:0 f:0 s:157
2017/09/21 08:23:53 [debug] 5#5: *1 http output filter "/?"
2017/09/21 08:23:53 [debug] 5#5: *1 http copy filter: "/?"
2017/09/21 08:23:53 [debug] 5#5: *1 http postpone filter "/?" 00005584A18B8478
...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Mukovoz, 2017-09-21
@castomi

Remove this line and it will work.
rewrite ^/test/?([^/]*) /$1 break;

K
klamas, 2017-10-03
@klamas

upstream server temporarily disabled while connecting to upstream, client: 10.80.2.244, server: myhost.ru, request: "GET /test HTTP/1.1", upstream: "127.0.0.1:10083", host: "myhost.ru"

This means that your
proxy_pass http://localhost:10083 option is not working;
You must replace localhost, which is your own in the nginx container and there is no open port 10083, with the IP of the server in which both containers work.
Another way is to run the nginx container with the "--network=host" key (in older docker versions --net=host). In this case, the nginx container will have host machine networks and port 10083 on localhost will be available there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question