![Jenkins 或 Apache 使用反向代理时更改 URL](https://linux22.com/image/752736/Jenkins%20%E6%88%96%20Apache%20%E4%BD%BF%E7%94%A8%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E6%97%B6%E6%9B%B4%E6%94%B9%20URL.png)
我有一个 VPS,用于运行个人 Gerrit 和 Jenkins 服务器。经过一年的忽视,我终于决定让它重新工作。以前我使用过gerrit.server.com
和jenkins.server.com
,但这导致了很多 https 认证问题,所以我决定直接转到子目录(?),例如server.com/jenkins
。我设法更新了 Gerrit 服务器并将其作为 server.com/gerrit 运行,但 Jenkins 实例就是无法工作。我昨天和今天早上几乎试了所有时间,但都没有成功。
这个问题似乎是反向代理和 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>
我希望这是一个发布此问题的正确社区。我不知道该做什么或搜索什么来解决这个问题。欢迎任何想法。
提前致谢
/Jaxc
答案1
您需要更新 $PREFIX 变量以适应新的 URI。这在您的 jenkins.xml 配置文件中,或将其添加为--prefix=/jenkins
命令行上的启动参数。
这是先前的答案。
答案2
今天我又尝试了一下,发现了我的错误:我把“”放错了位置,所以应该是
JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --prefix=$PREFIX"
曾是
JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT" "--prefix=$PREFIX"
一旦我解决了这个问题,一切都会开始按预期工作。