背景
公司全部網(wǎng)站需要支持 HTTPS 協(xié)議,在阿里云負(fù)載均衡配置 SSL 證書后,導(dǎo)致 Nexus 的 HTTPS 訪問出錯(cuò)。
網(wǎng)站訪問路徑: 域名解析到阿里云的負(fù)載均衡,負(fù)載均衡配置 80 端口強(qiáng)轉(zhuǎn) 443 端口,443 端口配置 SSL 證書,并轉(zhuǎn)發(fā)到內(nèi)網(wǎng) nginx,內(nèi)網(wǎng)的 nginx 再代理 Nexus 服務(wù)。
解決
瀏覽器 HTTPS 訪問 Nexus 的 Console 報(bào)錯(cuò)信息:
報(bào)錯(cuò)信息大致意思是:HTTPS 訪問的頁面上不允許出現(xiàn) HTTP 請(qǐng)求。
解決方法: 在 nginx 配置文件增加 “proxy_set_header X-Forwarded-Proto https;” ,這樣 nginx 在轉(zhuǎn)發(fā)時(shí)就使用 HTTPS 協(xié)議。
nginx.conf 中的 nexus 配置內(nèi)容:
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; # 轉(zhuǎn)發(fā)時(shí)使用https協(xié)議
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
}
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。