我一直在寻找一段时间,但我找不到适合我的情况的解决方案。所以这是我的情况:
我已经在我的公司安装了一个服务器,在该服务器上我有一个应用程序和一个用作代理的 apache 服务器。该服务器可以访问安装在网络(专用网络)上的一些设备。这些设备嵌入了一个网络服务器,我们可以从中配置设备(如家庭路由器)。所以,我想要的是能够将所有传入请求代理到设备。我想处理的方式是这样的:
用户可以使用该查询:
http://SERVER_IP:9090/10.219.1.1/
所以IP:10.219.1.1其实就是我喜欢访问的设备的IP。
到目前为止,这是我所做的:
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}/
结果:我能够加载 HTML 代码,但有两件事不起作用。
- 设备上的 CSS 尝试加载图像,我得到 400
- 我无法真正浏览设备菜单,因为 HREF 标签返回的 URL 不包含设备 IP 地址。例如:HREF 看起来像这样:
<a href="/cgi-bin/webif/status-network.sh?cat=Network">Network</a>
所以当我点击它时,它变成了:http://10.23.130.107:9090/cgi-bin/webif/status-network.sh?cat=Network
所以返回 URL 不包括设备的 IP 地址......
日志 :
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 - |-|-
我有另一个解决方案,但我不喜欢它。我可以为每个设备 IP 创建一个本地端口转发(带有 ip 表),但是这样做需要服务器上的很多端口,我认为这不是正确的方法。
感谢任何提示。
问候