天天看點

nginx rewrite重定向通路本地其它目錄,并且保留請求的位址和端口

背景

通過k8s通路http://192.168.1.2:32156/devops/index.html需跳轉到http://192.168.1.2:32156/jenkins/

配置檔案

location = /devops/index.html {             
    rewrite ^ $scheme://$http_host/jenkins/ permanent;      
}
location = /jenkins/ {
    root /usr/share/nginx/html;
    index /jenkins/index.html;
}      

相關解釋

location = /devops/index.html   #精準比對/devops/index.html
$scheme       #存放了用戶端請求使用的協定,如http
$http_host      #存放用戶端請求的位址+端口,如192.168.1.2:32156      

參考文章:

繼續閱讀