【问题标题】:Proxy request through Apache host to docker container通过 Apache 主机到 docker 容器的代理请求
【发布时间】:2017-10-18 17:16:59
【问题描述】:

我有一个运行 Apache Web 服务器的 Ubuntu 服务器主机。在此主机上运行的是一个为 Geoserver(通过 Tomcat)提供服务的 docker 容器(由此 image 构建),其端口配置如下:0.0.0.0:32770->8080/tcp

我可以使用 http://my.domain:32770/geoserver 访问 Geoserver
我在主机上的 Apache 中配置了一个重定向,以通过 HTTPS 服务所有请求(请参见下面的代码 sn-p),它不能很好地与这样的请求中的端口配合使用(即https://my.domain:32770/geoserver

<VirtualHost *:80>
        # sending http requests to https
        ServerName data.nrri.umn.edu
        Redirect permanent / https://data.nrri.umn.edu/
</VirtualHost>

我的解决方法是在 Apache 配置文件中使用 ProxyPass 指令:

ProxyRequests Off
ProxyPreserveHost On

ProxyPass /my-geoserver http://127.0.0.1:32770/geoserver
ProxyPassReverse /my-geoserver http://127.0.0.1:32770/geoserver

当我使用我期望的 URL 时,我会像上面那样进入 Geoserver 主页(即http://my.domain/my-geoserver),我被重定向到 https://my.domain/geoserver/index.html 并显示 404 Not Found。
我还应该注意http://my.domain:32770/geoserverhttp://my.domain:32770/geoserver/index.html 都解析为http://my.domain:32770/geoserver/web/

我在这里做错了什么?

编辑 来自curl -L -v -o /dev/null data.nrri.umn.edu/nra-geoserver的输出

* Hostname was NOT found in DNS cache
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 131.212.123.7...
* Connected to data.nrri.umn.edu (131.212.123.7) port 80 (#0)
> GET /nra-geoserver HTTP/1.1
> User-Agent: curl/7.35.0
> Host: data.nrri.umn.edu
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Fri, 19 May 2017 15:28:35 GMT
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Location: /geoserver/index.html
< Content-Length: 0
< Set-Cookie: JSESSIONID=DFECFFB91353A34C407488EAAF70A2B4; Path=/geoserver; HttpOnly
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host data.nrri.umn.edu left intact
* Issue another request to this URL: 'HTTP://data.nrri.umn.edu/geoserver/index.html'
* Found bundle for host data.nrri.umn.edu: 0x95b8c0
* Re-using existing connection! (#0) with host data.nrri.umn.edu
* Connected to data.nrri.umn.edu (131.212.123.7) port 80 (#0)
> GET /geoserver/index.html HTTP/1.1
> User-Agent: curl/7.35.0
> Host: data.nrri.umn.edu
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 19 May 2017 15:28:35 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< Location: https://data.nrri.umn.edu/geoserver/index.html
< Content-Length: 336
< Content-Type: text/html; charset=iso-8859-1
<
* Ignoring the response-body
{ [data not shown]
100   336  100   336    0     0  38536      0 --:--:-- --:--:-- --:--:-- 38536
* Connection #0 to host data.nrri.umn.edu left intact
* Issue another request to this URL: 'https://data.nrri.umn.edu/geoserver/index.html'
* Found bundle for host data.nrri.umn.edu: 0x95b8c0
* Hostname was NOT found in DNS cache
*   Trying 131.212.123.7...
* Connected to data.nrri.umn.edu (131.212.123.7) port 443 (#1)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS handshake, Server key exchange (12):
{ [data not shown]
* SSLv3, TLS handshake, Server finished (14):
{ [data not shown]
* SSLv3, TLS handshake, Client key exchange (16):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Finished (20):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
{ [data not shown]
* SSLv3, TLS handshake, Finished (20):
{ [data not shown]
* SSL connection using ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*        subject: C=US; ST=MN; L=Minneapolis; O=University of Minnesota; OU=Natural Resources Research Institute; CN=data.nrri.umn.edu
*        start date: 2017-04-18 00:00:00 GMT
*        expire date: 2020-04-17 23:59:59 GMT
*        subjectAltName: data.nrri.umn.edu matched
*        issuer: C=US; ST=MI; L=Ann Arbor; O=Internet2; OU=InCommon; CN=InCommon RSA Server CA
*        SSL certificate verify ok.
> GET /geoserver/index.html HTTP/1.1
> User-Agent: curl/7.35.0
> Host: data.nrri.umn.edu
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Fri, 19 May 2017 15:28:35 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< Content-Length: 301
< Content-Type: text/html; charset=iso-8859-1
<
{ [data not shown]
100   301  100   301    0     0   4404      0 --:--:-- --:--:-- --:--:--  4404
* Connection #1 to host data.nrri.umn.edu left intact

【问题讨论】:

  • 如果您做了任何附加操作,您能否阐明重定向的配置位置并提供它和 Tomcat 的相关配置?
  • 我添加了我在主机上的 Apache 重定向配置。至于在容器中运行的Tomcat,我还没有在那里做过任何事情,对Tomcat的配置也不是很熟悉;我按原样接受了 Dockerfile 中所做的工作。
  • 您可以尝试执行curl -L -v -o /dev/null http://my.domain/my-geoserver 并定位输出以便我们可以看到重定向标头吗?听起来这里几乎发生了两个重定向。我很困惑http://my.domain/my-geoserver 如何重定向到https://my.domain/geoserver/index.html
  • 好的。刚刚用该输出更新了问题。

标签: apache docker geoserver proxypass


【解决方案1】:

好的,所以发生了两个重定向。我不确定解决第一个问题的好方法(并且解决方案有可能解决它以及第二个问题)。但是第二个,您应该能够在路径中添加尾随/。生成的代理指令将是:

ProxyPass /my-geoserver/ http://127.0.0.1:32770/geoserver/
ProxyPassReverse /my-geoserver/ http://127.0.0.1:32770/geoserver/

先在http://data.nrri.umn.edu/geoserver/index.html 尝试一下,然后在http://data.nrri.umn.edu/nra-geoserver 上尝试一下,看看接下来会失败的地方。如果前者有效但后者失败,我们可能还需要编辑一些 Tomcat 配置(以启用远程 IP 阀https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html)。

【讨论】:

  • 我实现了您上面列出的更改,但同样的事情发生了,data.nrri.umn.edu/nra-geoserver 解析为 data.nrri.umn.edu/geoserver/index.html,我得到一个 404 Not Found 页面
  • 看起来它正在尝试访问 data.nrri.umn.edu 上的 /geoserver/index.html,但那里什么也没有。相反,geoserver 位于 data.nrri.umn.edu:32770(即 data.nrri.umn.edu:32770/geoserver)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-26
  • 2015-06-04
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 2014-03-01
相关资源
最近更新 更多