我有一个具有以下位置和上游配置的nginx容器:
upstream jenkins-docker {
server jenkins:8080 fail_timeout=0;
}
# configuration file /etc/nginx/conf-files/jenkins-location.conf:
location /jenkins/ {
sendfile off;
proxy_pass http://jenkins-docker;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host;
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_max_temp_file_size 0;
#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_request_buffering off; # Required for HTTP CLI commands in Jenkins > 2.54
}
Jenkins也在一个码头工人的容器中。它们都连接到docker桥接网络。在nginx-container里面,我可以做到:
curl jenkins:8080:
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->
</body></html>
nginx可以与詹金斯沟通。
在jenkins-&gt;管理Jenkins - &gt;在“Jenkins Location”下配置系统我将“Jenkins URL”更改为http://myIP/jenkins
当我输入我的浏览器myIp / jenkins时,它会重定向到http://myIp/login?from=%2Fjenkins%2F,这会导致404
当我将nginx中的位置“location / jenkins / {”更改为“/”时,它就像一个魅力。这就是为什么我尝试重写:
rewrite ^/jenkins(.*) /$1 break;
当我这样做时,我可以使用myIp / jenkis访问jenkins dashboar。但是当我点击一个菜单项时,我得到一个404
答案 0 :(得分:1)
您还需要在jenkins安装上设置--prefix命令。 Youi可以在jenkins.xml配置文件中执行此操作,也可以通过更改命令行参数来包含--prefix=/jenkins
。这些论点可以在https://wiki.jenkins.io/display/JENKINS/Starting+and+Accessing+Jenkins
答案 1 :(得分:1)
设置这样的环境变量:
JENKINS_OPTS="--prefix=/jenkins"
。
如果您使用的是docker-compose,则类似以下内容:
environment:
- JENKINS_OPTS="--prefix=/jenkins"