问题描述
使用nginx 对Jenkins做反向代理,nginx使用https协议,Jenkins使用http访问,用https://jenkins.com 访问可以正常进入首页,在首页里点击其他功能页时,跳转会自动请求协议为http的协议。所以我们需要将跳转其他功能页时,使用的协议也修改为https。
解决方式
需要在nginx配置中加入 proxy_set_header X-Forwarded-Proto $scheme; 这个请求头。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| server { listen 443 ssl; server_name jenkins.flashwhale.com; charset utf-8; ssl_certificate /etc/nginx/cert/jenkins/1_flashwhale.com_bundle.crt; ssl_certificate_key /etc/nginx/cert/jenkins/2_flashwhale.com.key;
location ~ /* { proxy_pass http://jenkins; proxy_set_header X-Rea $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Nginx-Proxy true; proxy_set_header X-Forwarded-Proto $scheme; } } server { listen 80; server_name jenkins.flashwhale.com;
rewrite ^(.*)$ https://$host$1 permanent; } upstream jenkins { server 127.0.0.1:8080; keepalive 64; }
|