I've been searching around for a time, and I can't find the right solution to my case. So here's my case :
I've installed a server in my company on which I've an application and a apache server used as a proxy. This server has access to some equipments installed on the network (private network). Those equipments has a webserver embedded from which we can configure the equipement (like a home router). So, what I want is to be able to proxy all incoming request to the equipment. The way I want to handle this is like this :
The user may use that query :
http://SERVER_IP:9090/10.219.1.1/
So the IP : 10.219.1.1 is in fact the IP of the equipment I like to access.
So far, here's what I've done :
SetEnvIf Referer ".*(10\.219\.[0-9]{1,3}\.[0-9]{1,3}).*$" routeur_ip=$1
SetEnvIf Request_URI ".*(10\.219\.[0-9]{1,3}\.[0-9]{1,3}).*$" routeur_ip=$1
RewriteRule ^\/10\.219\.[0-9]{1,3}\.[0-9]{1,3}\/$ http://%{ENV:routeur_ip}/ [P,L]
RewriteRule ^\/10\.219\.[0-9]{1,3}\.[0-9]{1,3}\/(.*)$ http://%{ENV:routeur_ip}/$1 [P,L]
RewriteRule ^\/(themes.*)$ http://%{ENV:routeur_ip}/$1?david=%{ENV:routeur_ip} [P,L]
RewriteRule ^\/(images.*)$ http://%{ENV:routeur_ip}/$1 [P,L]
RewriteRule ^\/(css.*)$ http://%{ENV:routeur_ip}/$1 [P,L]
RewriteRule ^\/(cgi-bin.*)$ http://%{ENV:routeur_ip}/$1 [P,L]
RewriteRule ^\/(js.*)$ http://%{ENV:routeur_ip}/$1 [P,L]
RewriteRule ^\/(favicon.ico)$ http://%{ENV:routeur_ip}/$1 [P,L]
ProxyPassReverse http://SERVER_IP:9090/%{ENV:routeur_ip}/ http://%{ENV:routeur_ip}/
Result : I'm able to load the HTML code, but two things doesn't work.
- The CSS on the equipment try to load an image and I get a 400
- I cannot navigate true the menu of the equipment, because the URL return by the HREF tag doesn't include the equipment IP address.
Ex.: The HREF looks like this :
<a href="/cgi-bin/webif/status-network.sh?cat=Network">Network</a>
So when I clik on this it became :http://10.23.130.107:9090/cgi-bin/webif/status-network.sh?cat=Network
So the return URL doesn't include the IP address of the equipment...
Log :
GET MY_IP 200, /10.219.1.1/ | Req_URI:/10.219.1.1/, HTTP_REF: | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /10.219.1.1/cgi-bin/webif/system-info.sh | Req_URI:/10.219.1.1/cgi-bin/webif/system-info.sh, HTTP_REF: | ip = 10.219.1.1 vs - |-|-
GET MY_IP 401, /10.219.1.1/cgi-bin/webif/system-info.sh | Req_URI:/10.219.1.1/cgi-bin/webif/system-info.sh, HTTP_REF: | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /themes/active/waitbox.css | Req_URI:/themes/active/waitbox.css, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /themes/active/webif.css | Req_URI:/themes/active/webif.css, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /js/styleswitcher.js | Req_URI:/js/styleswitcher.js, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /images/ajax-loader.gif | Req_URI:/images/ajax-loader.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /images/hlogo.gif | Req_URI:/images/hlogo.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /images/cell7.gif | Req_URI:/images/cell7.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 404, /images/cell7.gif | Req_URI:/images/cell7.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /10.219.1.1/cgi-bin/webif/system-info.sh | Req_URI:/10.219.1.1/cgi-bin/webif/system-info.sh, HTTP_REF: | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /js/styleswitcher.js | Req_URI:/js/styleswitcher.js, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /themes/active/waitbox.css | Req_URI:/themes/active/waitbox.css, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /themes/active/webif.css | Req_URI:/themes/active/webif.css, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 400, /themes/vip4g/menu-bg.gif | Req_URI:/themes/vip4g/menu-bg.gif, HTTP_REF:http://SERVER_IP:9090/themes/active/webif.css | ip = - vs - |-|-
GET MY_IP 400, /themes/vip4g/current-bg.gif | Req_URI:/themes/vip4g/current-bg.gif, HTTP_REF:http://SERVER_IP:9090/themes/active/webif.css | ip = - vs - |-|-
GET MY_IP 200, /images/ajax-loader.gif | Req_URI:/images/ajax-loader.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /images/hlogo.gif | Req_URI:/images/hlogo.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /10.219.1.1/cgi-bin/webif/system-info.sh | Req_URI:/10.219.1.1/cgi-bin/webif/system-info.sh, HTTP_REF: | ip = 10.219.1.1 vs - |-|-
GET MY_IP 200, /images/cell7.gif | Req_URI:/images/cell7.gif, HTTP_REF:http://SERVER_IP:9090/10.219.1.1/cgi-bin/webif/system-info.sh | ip = 10.219.1.1 vs - |-|-
I've another solution, but I doesn't like it. I could create a Local Port Fowarding (with ip tables) per Equipment IP, but it'll take a lot of ports on the server to do so and I don't think it's the right way to do it.
Thx for any hint.
Regards