首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Apache主机向docker容器发送代理请求

通过Apache主机向docker容器发送代理请求
EN

Stack Overflow用户
提问于 2017-05-18 18:32:01
回答 1查看 4K关注 0票数 1

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

我可以很好地使用http://my.domain:32770/geoserver访问Geoserver

在Apache中,我在主机上配置了一个重定向,用于通过HTTPS服务所有请求(请参阅下面的代码片段),它不能很好地处理像这样的请求中的端口(即。https://my.domain:32770/geoserver)

代码语言:javascript
复制
<VirtualHost *:80>
        # sending http requests to https
        ServerName data.nrri.umn.edu
        Redirect permanent / https://data.nrri.umn.edu/
</VirtualHost>

解决这一问题的方法是在Apache文件中使用ProxyPass指令:

代码语言:javascript
复制
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。

我还应该注意到,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的输出

代码语言:javascript
复制
* 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
EN

回答 1

Stack Overflow用户

发布于 2017-05-19 20:00:51

好的,有两个重定向正在发生。我不确定解决第一个问题的好方法(解决方案可能解决第一个问题,也可能解决第二个问题)。但是第二个,您应该能够在路径中添加一个尾随的/。由此产生的代理指令如下:

代码语言:javascript
复制
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)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44055414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档