LINUX.ORG.RU
ФорумAdmin

Nginx frontend docker freepbx backend

 , , , ,


0

1

Хочу начать потихоньку осваивать зверя freepbx для общего развития. Так как был уже случай с ним связанный (навыки астериска не сильно там пригодились).

Так вот у меня проблема с upstream nginx. Он как-то неправильно проксирует. Наверное есть какой-то особый заголовок который нужно передать, но мне о нем неизвестно.

Схема такая:

Internet -> Nginx Reverse [80 порт] -> docker(freepbx) [9972 порт]
Nginx и докер на одной машине
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3552/nginx -g daemo
tcp6       0      0 :::9972                 :::*                    LISTEN      13697/docker-proxy
f493867c0e56        mima84/docker-freepbx        "/sbin/my_init"          10 hours ago        Up 10 hours         0.0.0.0:5060->5060/udp, 0.0.0.0:5160-5161->5160-5161/udp, 0.0.0.0:10000-10050->10000-10050/udp, 0.0.0.0:9972->8082/tcp   freepbx

nginx conf

upstream tofreepbx {                                               
  server 127.0.0.1:9972;                                           
}                                                                  
                                                                   
server {                                                           
    listen       80;                                               
    server_name  freepbx.local.com;                                
                                                                   
  location / {                                                     
    proxy_pass http://tofreepbx;                                   
    #proxy_pass http://127.0.0.1:9972;                              
    #proxy_redirect     off;                               
    #proxy_set_header   Host $host;                        
    #proxy_http_version 1.1;                                       
    #proxy_set_header Upgrade $http_upgrade;                       
    #proxy_set_header Connection "";                               
    #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  }                                                                
                                                                   
                                                                   
}

если проксировать без Upstream сразу на proxy_pass http://127.0.0.1:9972; то нормально проксирует.

* Rebuilt URL to: http://freepbx.local.com/
*   Trying 127.0.0.1...
* Connected to freepbx.local.com (127.0.0.1) port 80 (#0)
> HEAD / HTTP/1.1
> Host: freepbx.local.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
HTTP/1.1 302 Found
< Server: nginx
Server: nginx
< Date: Thu, 11 Jul 2019 18:58:47 GMT
Date: Thu, 11 Jul 2019 18:58:47 GMT
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Connection: keep-alive
Connection: keep-alive
< Location: /admin
Location: /admin

<
* Connection #0 to host freepbx.local.com left intact
* Issue another request to this URL: 'http://freepbx.local.com/admin'
* Found bundle for host freepbx.local.com: 0x55bc340be8e0 [can pipeline]
* Re-using existing connection! (#0) with host freepbx.local.com
* Connected to freepbx.local.com (127.0.0.1) port 80 (#0)
> HEAD /admin HTTP/1.1
> Host: freepbx.local.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Server: nginx
Server: nginx
< Date: Thu, 11 Jul 2019 18:58:47 GMT
Date: Thu, 11 Jul 2019 18:58:47 GMT
< Content-Type: text/html; charset=iso-8859-1
Content-Type: text/html; charset=iso-8859-1
< Location: http://freepbx.local.com/admin/
Location: http://freepbx.local.com/admin/
< Connection: keep-alive
Connection: keep-alive

<
* Connection #0 to host freepbx.local.com left intact
* Issue another request to this URL: 'http://freepbx.local.com/admin/'
* Found bundle for host freepbx.local.com: 0x55bc340be8e0 [can pipeline]
* Re-using existing connection! (#0) with host freepbx.local.com
* Connected to freepbx.local.com (127.0.0.1) port 80 (#0)
> HEAD /admin/ HTTP/1.1
> Host: freepbx.local.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
HTTP/1.1 302 Found
< Server: nginx
Server: nginx
< Date: Thu, 11 Jul 2019 18:58:47 GMT
Date: Thu, 11 Jul 2019 18:58:47 GMT
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Connection: keep-alive
Connection: keep-alive
< Location: config.php
Location: config.php

<
* Connection #0 to host freepbx.local.com left intact
* Issue another request to this URL: 'http://freepbx.local.com/admin/config.php'
* Found bundle for host freepbx.local.com: 0x55bc340be8e0 [can pipeline]
* Re-using existing connection! (#0) with host freepbx.local.com
* Connected to freepbx.local.com (127.0.0.1) port 80 (#0)
> HEAD /admin/config.php HTTP/1.1
> Host: freepbx.local.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx
Server: nginx
< Date: Thu, 11 Jul 2019 18:58:47 GMT
Date: Thu, 11 Jul 2019 18:58:47 GMT
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
< Connection: keep-alive
Connection: keep-alive
< Last-Modified: Thu, 11 Jul 2019 18:58:47 GMT
Last-Modified: Thu, 11 Jul 2019 18:58:47 GMT
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
Pragma: no-cache
< Set-Cookie: PHPSESSID=mkshe46aojoimf9eidu6i1v853; expires=Sat, 10-Aug-2019 18:58:47 GMT; Max-Age=2592000; path=/
Set-Cookie: PHPSESSID=mkshe46aojoimf9eidu6i1v853; expires=Sat, 10-Aug-2019 18:58:47 GMT; Max-Age=2592000; path=/
< Set-Cookie: lang=en_US
Set-Cookie: lang=en_US

<
* Connection #0 to host freepbx.local.com left intact

Если с Upstream, то так:

* Rebuilt URL to: http://freepbx.local.com/
*   Trying 127.0.0.1...
* Connected to freepbx.local.com (127.0.0.1) port 80 (#0)
> HEAD / HTTP/1.1
> Host: freepbx.local.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
HTTP/1.1 302 Found
< Server: nginx
Server: nginx
< Date: Thu, 11 Jul 2019 13:59:02 GMT
Date: Thu, 11 Jul 2019 13:59:02 GMT
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Connection: keep-alive
Connection: keep-alive
< Location: /admin
Location: /admin

<
* Connection #0 to host freepbx.local.com left intact
* Issue another request to this URL: 'http://freepbx.local.com/admin'
* Found bundle for host freepbx.local.com: 0x564db87908e0 [can pipeline]
* Re-using existing connection! (#0) with host freepbx.local.com
* Connected to freepbx.local.com (127.0.0.1) port 80 (#0)
> HEAD /admin HTTP/1.1
> Host: freepbx.local.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Server: nginx
Server: nginx
< Date: Thu, 11 Jul 2019 13:59:02 GMT
Date: Thu, 11 Jul 2019 13:59:02 GMT
< Content-Type: text/html; charset=iso-8859-1
Content-Type: text/html; charset=iso-8859-1
< Connection: keep-alive
Connection: keep-alive
< Location: http://tofreepbx:8082/admin/
Location: http://tofreepbx:8082/admin/

<
* Connection #0 to host freepbx.local.com left intact
* Issue another request to this URL: 'http://tofreepbx:8082/admin/'
* Could not resolve host: tofreepbx
* Closing connection 1
curl: (6) Could not resolve host: tofreepbx



Последнее исправление: sanekmihailow (всего исправлений: 2)

У тебя freepbx перенаправляет браузер на /admin своего внутреннего домена, который браузеру не виден.

LamerOk ★★★★★
()
Ответ на: комментарий от LamerOk

Почему тогда перенаправление нормально работает, если сделать так?

server {                                                           
    listen       80;                                               
    server_name  freepbx.local.com;                                
                                                                   
  location / {                                                                                  
    proxy_pass http://127.0.0.1:9972;
  }
}
sanekmihailow
() автор топика

Короче помогло явно задать заголовок хоста

upstream tofreepbx {
  server 127.0.0.1:9972;
}

server {
    listen       80;
    server_name  freepbx.local.com;

  location / {
    proxy_pass  http://tofreepbx;
    proxy_set_header Host            freepbx.local.com:80;
    proxy_set_header X-Forwarded-For $remote_addr;
  }

}
sanekmihailow
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.