背景
公司全部網站需要支持 HTTPS 協議,在阿里雲負載均衡配置 SSL 證書后,導致 Nexus 的 HTTPS 訪問出錯。
網站訪問路徑: 域名解析到阿里雲的負載均衡,負載均衡配置 80 端口強轉 443 端口,443 端口配置 SSL 證書,並轉發到內網 nginx,內網的 nginx 再代理 Nexus 服務。
解決
瀏覽器 HTTPS 訪問 Nexus 的 Console 報錯信息:
報錯信息大致意思是:HTTPS 訪問的頁面上不允許出現 HTTP 請求。
解決方法: 在 nginx 配置文件增加 “proxy_set_header X-Forwarded-Proto https;” ,這樣 nginx 在轉發時就使用 HTTPS 協議。
nginx.conf 中的 nexus 配置內容:
location ^~ /nexus {
proxy_pass http://x.x.x.x:8080/nexus;
sendfile off;
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 https; # 轉發時使用https協議
proxy_max_temp_file_size 0;
# This is the maximum upload size
client_max_body_size 20m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_temp_file_write_size 64k;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off; # Required for HTTP-based CLI to work over SSL
}
微信公眾號:daodaotest