簡體   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