【问题标题】:Proxy reversing SSL server in ApacheApache中的代理反向SSL服务器
【发布时间】:2018-08-23 01:18:29
【问题描述】:

我正在努力使用代理在 Apache 中反转 SSL 服务器。 现在我在一个域中的许多子域下有许多网站。
例如:

gitlab.mydomain.com
nextcloud.mydomain.com
plex.mydomain.com

所有网站都使用 Letsencrypt 证书,因此它们都启用了 HTTPS。

问题是,到目前为止,在我的本地主机上运行的服务器都不是 HTTPS。例如,Plex 在我的本地主机上作为独立的 HTTP 服务器运行,我只是使用 Apache 进行反向代理,并在互联网上使用 Letsencrypt 保护它。

现在我需要代理反向一个已经安全的 HTTP 服务器。即 Jenkins - 由于各种原因,它在我的本地主机上与 Letsencrypt 一起运行。我还应该提到,用于在 localhost 上加密它的证书与我在 Apache 中使用的证书相同。

所以我的 Jenkins 在端口 8443 上运行,我的 Jenkins 的 Apache 配置如下:

# Just to redirect HTTP to HTTPS
<VirtualHost *:80>
  ServerName jenkins.mydomain.com
  ServerAlias www.jenkins.mydomain.com
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<Virtualhost *:443>
    ServerName jenkins.mydomain.com
    ServerAlias https://jenkins.mydomain.com
    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    <Proxy https://localhost:8443/jenkins*>
      Order deny,allow
      Allow from all
    </Proxy>

    ProxyPass         /jenkins  http://localhost:8443/jenkins nocanon
    ProxyPassReverse  /jenkins  http://localhost:8443/jenkins
    ProxyPassReverse  /jenkins  http://jenkins.mydomain.com/jenkins
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"
    RequestHeader set X-Forwarded-Ssl on

    RewriteEngine on
    RewriteRule   "^/$"  "/jenkins/"  [R]

    SSLEngine on
    SSLCertificateFile  path/to/fullchain.pem
    SSLCertificateKeyFile path/to/privkey.pem
</Virtualhost>

但是,使用此配置时,我收到 错误 502(代理错误)

代理服务器收到来自上游服务器的无效响应。 代理服务器无法处理请求 GET /jenkins/。 原因:从远程服务器读取错误

【问题讨论】:

    标签: apache ssl jenkins reverse-proxy


    【解决方案1】:

    您收到的 502 是因为 Apache 没有收到来自 http://localhost:8443/jenkins 的响应。这是在其他任何事情都可以工作之前需要解决的第一个问题。确保您能够使用 cURL 访问 Jenkins。

    例如:curl http://localhost:8443/jenkins 如果没有响应然后尝试curl https://localhost:8443/jenkins 如果没有响应,那么我会看看 Jenkins 是否配置正确。

    我注意到有几件事应该在您的虚拟主机配置中进行更新。

    1. ServerAlias https://jenkins.mydomain.com 应该是 ServerAlias www.jenkins.mydomain.com,因为 https:// 不应包含在 ServerAlias 指令中,而且您可能希望能够使用 https://www.jenkins.mydomain.com 访问该站点,因为这是非-https 指令。您也很可能希望在您的 https 虚拟主机中包含一个重写,将 www.jenkins.mydomain.com 重写为 jenkins.mydomain.com

    2. 您可能不需要第二个 ProxyPassReverse 指令。

    【讨论】:

    • 感谢您的回答,但 Jenkins 在 localhost (https://localhost:8443/jenkins) 上运行良好,并且当 jenkins 运行 HTTP 而不是 HTTPS 时,此配置正常工作。
    • 好的,但您仍然收到 502?
    • 仅当我通过 jenkins.mydomain.com 上的 Apache 访问它时。基于此,我认为只有代理反向是错误的。但说实话,配置 Apache 并不是我的强项。
    • 好的。让我快速测试一些东西,看看这个。
    猜你喜欢
    • 2013-05-22
    • 2013-04-02
    • 1970-01-01
    • 2019-03-30
    • 2019-06-30
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    相关资源
    最近更新 更多