繁体   English   中英

Apache中的代理反向SSL服务器

[英]Proxy reversing SSL server in Apache

我正在为Apache中的SSL服务器反向代理而苦苦挣扎。 现在,我在一个域的许多子域下有许多网站。
例如:

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

所有网站均使用Letsencrypt证书,因此已启用HTTPS。

事实是,到目前为止,在我的本地主机上运行的服务器都不是HTTPS。 例如,Plex在我的本地主机上作为独立的HTTP服务器运行,我只是使用Apache代理反向代理,而在Internet上它由Letsencrypt保护。

现在,我需要代理反向已安全的HTTP服务器。 即Jenkins-由于各种原因,它在我的本地主机上与Letsencrypt一起运行。 我还应该提到,用于在本地主机上对其进行加密的证书与我在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 /请求。 原因:从远程服务器读取错误

您得到的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://www.jenkins.mydomain.com因为它位于非https指令中。 您还很可能希望在https虚拟主机中www.jenkins.mydomain.comjenkins.mydomain.com重写为jenkins.mydomain.com重写。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM