apache反向代理域名訪問,獲取到內網ip,而不是代理ip
給客戶組專案,配置了域名,訪問域名時,總是訪問的是內網ip,這樣直接暴露內網ip不合規定,所以先審查程式碼,
jsp原先寫法:
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href="<%=basePath%>">
這樣總是獲取真實ip,所以修改為StringBuffer url = request.getRequestURL();//獲取請求網址
String basePath = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getContextPath()).append("/").toString();
然後檢視apache代理配置,發現配置錯誤,把httpd.conf修改後的程式碼貼上在下面:
# Virtual hosts 開啟虛擬主機的配置
#Include conf/extra/httpd-vhosts.conf
ProxyRequests off
ProxyPreserveHost On #開啟host域名請求地址,如果使用代理,獲取的請求地址是對外域名,如果off關閉,則獲取的是內網ip地址請求
<Proxy balancer://proxy>
Order Deny,Allow
Allow from all
BalancerMember http://192.168.0.150:8089 status=+H
BalancerMember http://192.168.0.150:8090
</Proxy>
ProxyPass / balancer://proxy/
ProxyPassReverse / balancer://proxy/ #直接跳轉到域名地址,如果不配置,系統直接轉發到內網ip地址上面
TraceEnable Off