Задать вопрос
Slavenin999
@Slavenin999
программист php/erlang/elixir/js

Почему не работает перенаправление в контейнер из nginx?

Доброго времени суток!
Есть два контейнера в одном nginx в другом redmine.
У редмайна открыт порт и если обращаться напрямую на этот порт из браузера, то всё ок.
Поставил контейнер с nginx.
Создал конфиг:
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;
    }

}

но при обращении на myhost.ru/test получается 502. При этом в логе самого редмайна обращения к нему нет. Что я сделал не так?

лог nginx:
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
...
  • Вопрос задан
  • 4819 просмотров
Подписаться 1 Простой 8 комментариев
Пригласить эксперта
Ответы на вопрос 2
castomi
@castomi
Серверный администратор - tickets.settin.ru
Удали вот эту строку и всё заработает.
rewrite ^/test/?([^/]*) /$1 break;
Ответ написан
Комментировать
@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"


Это говорит о том, что не работает ваша опция
proxy_pass http://localhost:10083;

Вы должны заменить localhost, который в контейнере nginx свой и там нет открытого порта 10083, на IP сервера в котором работают оба контейнера.

Другой способ: запускать nginx-контейнер с ключем "--network=host" (в старых версиях докера --net=host). В этом случае в nginx-контейнере будут сети хост-машины и там будет доступен порт 10083 на localhost.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы