我正在尝试使用2个docker容器设置一个基本模型(用于培训):
nginx用作反向容器(下一步将是https前端)。 詹金斯应该可以通过www.devportal.org:90/ci
公开访问。我有部分成功。我的意思是我可以使用给定的地址访问它。但是...
当我尝试与管理员用户连接时,我得到登录页面。但是在填写用户名/密码时,我被重定向到http://www.devportal.org/ci/。
如果将端口添加到该地址,则会获得实例主页,该页面以管理员用户身份连接。
当选择管理页面时,我看到一条警告消息,指出我的反向代理配置已损坏。
此外,在配置系统时,页面会显示,但永远不会完成加载。
我为nginx尝试了各种配置,但是没有一个给我正确的结果。
Jenkins位置URL设置为nginx已知的实例地址。
只要两者都在链接到专用docker网络(其中jenkins被称为jenkins_ci)的容器内,地址为http://jenkins_ci:8080/ci/。
如果我跑步:
docker exec nginx_revproxy wget http://jenkins_ci:8080/ci/
我实际上得到了主页。
这是我的nginx配置(在/etc/nginx/conf.d/reverse_proxy.conf中)
# Reverse proxy configuration for one jenkins server
# Nginx listen public traffic on port 90 and forward to jenkins container address on port 8080
server {
listen 90;
access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;
location ^~ /ci/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://jenkins_ci:8080/ci/;
# Fix the "It appears that your reverse proxy set up is broken" error.
proxy_set_header X-Forwarded-Host $host;
proxy_read_timeout 90;
proxy_redirect http://jenkins_ci:8080/ http://www.devportal.org:90/;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
}
}
在连接时出现错误页面时,我在nginx容器日志中看到了这一点
172.17.0.1 - - [19/Jul/2019:12:32:04 +0000] "GET /ci/ HTTP/1.1" 404 153 "http://www.devportal.org:90/ci/login?from=/ci/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0" "-"
2019/07/19 12:32:04 [error] 7#7: *40 "/usr/share/nginx/html/ci/index.html" is not found (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /ci/ HTTP/1.1", host: "www.devportal.org", referrer: "http://www.devportal.org:90/ci/login?from=/ci/"
在詹金斯容器日志中,我也有:
Jul 19, 2019 2:18:25 PM hudson.diagnosis.ReverseProxySetupMonitor getTestForReverseProxySetup
WARNING: http://www.devportal.org/ci/manage vs. http:
其他信息 使用nginx conf:
server {
listen 90;
server_name www.devportal.org;
access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;
location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
#rewrite all static files into requests to the root
#E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}
location /ci/ {
proxy_pass http://jenkins_ci:8080;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Fix the "It appears that your reverse proxy set up is broken" error.
proxy_set_header X-Forwarded-Host $host;
proxy_read_timeout 90;
proxy_redirect http://jenkins_ci:8080/ http://www.devportal.org:90/;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_set_header Connection ""; # Clear for keepalive
}
}
和
<jenkins.model.JenkinsLocationConfiguration>
<adminAddress>[my mail address]</adminAddress>
<jenkinsUrl>http://www.devportal.org:90/ci</jenkinsUrl>
</jenkins.model.JenkinsLocationConfiguration>
在
jenkins.model.JenkinsLocationConfiguration.xml
关于jenkins日志中的错误消息,我取得了一些进展:
Jul 22, 2019 11:59:35 AM hudson.diagnosis.ReverseProxySetupMonitor getTestForReverseProxySetup
WARNING: http://www.devportal.org/ci/manage vs. http://www.devportal.org:90/ci/manage
现在,我只松开端口号(之前我丢失了整个域名)。 请注意,无论是否使用proxy_redirect,它都是相同的。
答案 0 :(得分:1)
因此,应该将Jenkins URL设置为用户在描述中所看到的URL:
Optionally specify the HTTP address of the Jenkins installation, such as
http://yourhost.yourdomain/jenkins/. This value is used to let Jenkins know how
to refer to itself, ie. to display images or to create links in emails. This is
necessary because Jenkins cannot reliably detect such a URL from within itself
因此,您的情况是:http://www.devportal.org:90/
应该删除该行,因为我认为这是不必要的:
proxy_redirect http://jenkins_ci:8080/ http://www.devportal.org:90/;
您应该像这样从代理通行证中删除“ / ci”
proxy_pass http://jenkins_ci:8080;