我正在使用 docker 部署 jenkins 和 nginx,但我不想导出 80(出于安全考虑),所以我使用以下 docker compose:services:jenkins:image:jenkins/jenkins:lts volumes:...
我正在使用 docker 部署 jenkins 和 nginx,但我不想导出 80(出于安全考虑),所以我使用以下 docker compose:
services:
jenkins:
image: jenkins/jenkins:lts
volumes:
- ./jenkins_home:/var/jenkins_home
ssh-agent:
image: jenkins/ssh-agent
nginx:
image: nginx:latest
ports:
- "10086:80"
- "10087:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- jenkins
和 nginx 配置文件:
server {
listen 80;
server_name ci.xxx.com;
location / {
proxy_pass http://jenkins:8080;
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_redirect off;
}
location /ws/ {
proxy_pass http://jenkins:8080/ws/;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
location /static/ {
proxy_pass http://jenkins:8080/static/;
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;
}
location /api/ {
proxy_pass http://jenkins:8080/api/;
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;
}
}
然后,我在 Jenkins 配置中将 jenkins_url 设置为 http://ci.xxx.com:10086/
,并重新启动容器。然后我成功访问 http://ci.xxx.com:10086
并重定向到 http://ci.xxx.com:10086/login
。但是当我按下登录按钮时,它会重定向到 http://ci.xxx.com
(否 :10086
),然后失败了。