Apache2

Jenkins 或 Apache 在使用反向代理時更改 URL

  • August 9, 2020

我有一個用於執行個人 Gerrit 和 Jenkins 伺服器的 VPS。經過一年的忽視,我終於決定讓它再次工作。以前我使用過gerrit.server.comand jenkins.server.com,但這會導致 https 認證出現很多問題,所以我決定直接轉到子目錄(?),例如server.com/jenkins. 我設法更新了 Gerrit 伺服器並作為 server.com/gerrit 工作,但 Jenkins 實例無法正常工作。我昨天和今天早上幾乎都試過了,但沒有運氣。

這個問題似乎是 revese 代理和 Jenkins 之間的切換存在某種問題,因為當我寫server.com/jenkins的時候被重定向(?)到server.com/login?from=%2Fjenkins%2F. 我認為 Jenkins 以某種方式被呼叫,然後認為這/jenkins是一個論據,但我對 apache 的工作方式不是很好。

如果我嘗試通過訪問 server.com:8081 直接訪問 jenkins 伺服器,它會按預期工作。

我的apache配置如下:

<VirtualHost *:80>
       # The ServerName directive sets the request scheme, hostname and port that
       # the server uses to identify itself. This is used when creating
       # redirection URLs. In the context of virtual hosts, the ServerName
       # specifies what hostname must appear in the request's Host: header to
       # match this virtual host. For the default virtual host (this file) this
       # value is not decisive as it is used as a last resort host regardless.
       # However, you must set it for any further virtual host explicitly.
       #ServerName www.example.com

       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/html

       ServerName www.<serverURL>.com

       # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
       # error, crit, alert, emerg.
       # It is also possible to configure the loglevel for particular
       # modules, e.g.
       #LogLevel info ssl:warn
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined

       # For most configuration files from conf-available/, which are
       # enabled or disabled at a global level, it is possible to
       # include a line for only one particular virtual host. For example the
       # following line enables the CGI configuration for this host only
       # after it has been globally disabled with "a2disconf".
       #Include conf-available/serve-cgi-bin.conf

       ProxyPass "/jenkins" "http://localhost:8081/jenkins/" nocanon
       ProxyPassReverse "/jenkins" "http://localhost:8081/jenkins/"

       ProxyRequests     Off
       ProxyPreserveHost On
       AllowEncodedSlashes On

       ProxyPass "/gerrit" http://localhost:8080/gerrit nocanon
       ProxyPassReverse "/gerrit" "http://localhost:8080/gerrit"

       <Proxy *>
         Require all granted
       </Proxy>

</VirtualHost>

我希望這是發布此問題的正確社區。我完全不知道該怎麼做或搜尋什麼來解決這個問題。歡迎任何想法。

提前致謝

/賈克斯

我今天又拍了一張,發現我的錯誤:我已經設法放錯了我的“”,所以應該是

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --prefix=$PREFIX"

曾是

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT" "--prefix=$PREFIX"

一旦我解決了這個問題,一切都開始按預期工作。

您需要為新的 URI 更新 $PREFIX 變數。這在您的 jenkins.xml 配置文件中,或者將其作為啟動參數添加--prefix=/jenkins到命令行中。

這是之前的答案。

https://stackoverflow.com/a/9119377/13483200

引用自:https://serverfault.com/questions/1018223