首页 文章

代理在Apache中反转SSL服务器

提问于
浏览
0

我正在努力解决Apache中的SSL服务器代理问题 . 现在我在一个域中的许多子域下有很多网站 .
例如:

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

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

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

现在我需要代理反向已经安全的HTTP服务器 . 即Jenkins - 由于各种原因,它在我的localhost上运行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>

但是,使用此配置,我得到 error 502 (Proxy Error)

代理服务器从上游服务器收到无效响应 . 代理服务器无法处理请求GET / jenkins / . 原因:从远程服务器读取时出错

1 回答

  • 0

    502你're getting is because Apache isn'收到 http://localhost:8443/jenkins 的回复 . 这是在其他任何工作之前需要解决的第一个问题 . 确保您可以使用 cURL 访问Jenkins .

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

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

    • ServerAlias https://jenkins.mydomain.com 应为 ServerAlias www.jenkins.mydomain.com ,因为 https:// 不应包含在 ServerAlias 指令中,而且您可能希望能够使用 https://www.jenkins.mydomain.com 到达该站点,因为这是在非https指令中 . 您也很可能希望在https虚拟主机中包含重写 www.jenkins.mydomain.comjenkins.mydomain.com .

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

相关问题