需要有关 nginx 反向代理(和 jenkins ?)配置的帮助
Need help about nginx reverse proxy (and jenkins ?) configuration
我正在尝试使用 2 个 docker 容器设置一个基本模型(用于训练):
- 一个使用 nginx
- 詹金斯一个
nginx作为反向容器使用(下一步是https前端)。
jenkins 应该可以公开访问 www.devportal.org:90/ci
我已经部分成功了。我的意思是我可以使用给定的地址访问它。但是...
当我尝试连接管理员用户时,我看到了登录页面。但是当填写用户/密码时,我被重定向到 http://www.devportal.org/ci/.
如果我将端口添加到该地址,我将获得实例主页,以管理员用户身份连接。
当我 select 管理页面时,我看到一条警告消息说我的反向代理配置已损坏。
此外,配置系统时,页面显示但始终加载不完。
我尝试了 nginx 的各种配置,但其中 none 给了我正确的结果。
Jenkins Location 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/"
在 jenkins 容器日志上我还有:
Jul 19, 2019 2:18:25 PM hudson.diagnosis.ReverseProxySetupMonitor getTestForReverseProxySetup
WARNING: http://www.devportal.org/ci/manage vs. http:
附加信息
使用 nginx 配置文件:
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}\/(.*)" / 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都一样。
因此 Jenkins 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;
我正在尝试使用 2 个 docker 容器设置一个基本模型(用于训练):
- 一个使用 nginx
- 詹金斯一个
nginx作为反向容器使用(下一步是https前端)。 jenkins 应该可以公开访问 www.devportal.org:90/ci
我已经部分成功了。我的意思是我可以使用给定的地址访问它。但是...
当我尝试连接管理员用户时,我看到了登录页面。但是当填写用户/密码时,我被重定向到 http://www.devportal.org/ci/.
如果我将端口添加到该地址,我将获得实例主页,以管理员用户身份连接。
当我 select 管理页面时,我看到一条警告消息说我的反向代理配置已损坏。
此外,配置系统时,页面显示但始终加载不完。
我尝试了 nginx 的各种配置,但其中 none 给了我正确的结果。
Jenkins Location 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/"
在 jenkins 容器日志上我还有:
Jul 19, 2019 2:18:25 PM hudson.diagnosis.ReverseProxySetupMonitor getTestForReverseProxySetup
WARNING: http://www.devportal.org/ci/manage vs. http:
附加信息 使用 nginx 配置文件:
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}\/(.*)" / 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都一样。
因此 Jenkins 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;