redirectsudirectory请求到局域网中的另一个IP

我试图redirect/networkingmyfakedomain.com到局域网中的另一个ip xxx.xxx.xxx.120。

也就是说,当我尝试访问myfakedomain.com/net时,它应该显示xxx.xxx.xxx.120的内容

我也正在将http请求redirect到https,如下所示

<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName myfakedomain.com Redirect 301 / https://myfakedomain.com/ ServerAdmin webmaster@localhost </VirtualHost> <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName www.myfakedomain.com Redirect 301 / https://www.myfakedomain.com/ ServerAdmin webmaster@localhost </VirtualHost> <VirtualHost *:443> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName myfakedomain.com ServerAdmin webmaster@localhost RewriteEngine on # just in case (don't want to accidentally expose all the internal servers) ! ProxyRequests off # define a log file LogLevel warn rewrite:trace3 # add the tailing / if not there RewriteRule ^/net$ https://myfakedomain.com/net/ [R] [L] # proxy the request to internal url RewriteRule ^/net/* http://xxx.xxx.xxx.120/$1 [P] SSLEngine On SSLCertificateFile /etc/letsencrypt/live/myfakedomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/myfakedomain.com/privkey.pem DocumentRoot /var/www/html/myfakedomain <Directory /var/www/html/myfakedomain/> Options Indexes FollowSymLinks MultiViews AllowOverride All </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> <VirtualHost *:443> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName www.myfakedomain.com ServerAdmin webmaster@localhost RewriteEngine on # just in case (don't want to accidentally expose all the internal servers) ! ProxyRequests off # define a log file LogLevel warn rewrite:trace3 # add the tailing / if not there RewriteRule ^/net$ https://www.myfakedomain.com/net/ [R] [L] # proxy the request to internal url RewriteRule ^/net/* http://xxx.xxx.xxx.120/$1 [P] SSLEngine On SSLCertificateFile /etc/letsencrypt/live/myfakedomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/myfakedomain.com/privkey.pem DocumentRoot /var/www/html/myfakedomain <Directory /var/www/html/myfakedomain/> Options Indexes FollowSymLinks MultiViews AllowOverride All </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

它试图从xxx.xxx.xxx.120加载页面,但是所有图像,css和js都试图从myfakedomain.com加载如下

 GET https://myfakedomain.com/themes/default/js/functions.js 404 (Not Found) 

因此无法加载404未find。

我尝试使用mod_proxy_html,下面是我的虚拟主机conf文件。 还是一样的,唯一不同的是,所有的图像都有一个边框(轮廓),而这些边框并不在之前。

 <VirtualHost *:80> ServerName myfakedomain.com ServerAdmin webmaster@localhost Redirect 301 / https://myfakedomain.com/ </VirtualHost> <VirtualHost *:80> ServerName www.myfakedomain.com ServerAdmin webmaster@localhost Redirect 301 / https://www.myfakedomain.com/ </VirtualHost> <VirtualHost *:443> ServerName myfakedomain.com ServerAdmin webmaster@localhost <Location /net> ProxyHTMLLinks a href ProxyHTMLLinks area href ProxyHTMLLinks link href ProxyHTMLLinks img src longdesc usemap ProxyHTMLLinks object classid codebase data usemap ProxyHTMLLinks q cite ProxyHTMLLinks blockquote cite ProxyHTMLLinks ins cite ProxyHTMLLinks del cite ProxyHTMLLinks form action ProxyHTMLLinks input src usemap ProxyHTMLLinks head profile ProxyHTMLLinks base href ProxyHTMLLinks script src for ProxyHTMLEvents onclick ondblclick onmousedown onmouseup \ onmouseover onmousemove onmouseout onkeypress \ onkeydown onkeyup onfocus onblur onload \ onunload onsubmit onreset onselect onchange ProxyPass http://xxx.xxx.xxx.120/ ProxyPassReverse http://xxx.xxx.xxx.120/ ProxyHTMLEnable On ProxyHTMLExtended On SetOutputFilter INFLATE;proxy-html;DEFLATE; ProxyHTMLURLMap http://xxx.xxx.xxx.120/ /net </Location> SSLEngine On SSLCertificateFile /etc/letsencrypt/live/myfakedomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/myfakedomain.com/privkey.pem DocumentRoot /var/www/html/myfakedomain <Directory /var/www/html/myfakedomain/> Options Indexes FollowSymLinks MultiViews AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> <VirtualHost *:443> ServerName www.myfakedomain.com ServerAdmin webmaster@localhost <Location /net> ProxyHTMLLinks a href ProxyHTMLLinks area href ProxyHTMLLinks link href ProxyHTMLLinks img src longdesc usemap ProxyHTMLLinks object classid codebase data usemap ProxyHTMLLinks q cite ProxyHTMLLinks blockquote cite ProxyHTMLLinks ins cite ProxyHTMLLinks del cite ProxyHTMLLinks form action ProxyHTMLLinks input src usemap ProxyHTMLLinks head profile ProxyHTMLLinks base href ProxyHTMLLinks script src for ProxyHTMLEvents onclick ondblclick onmousedown onmouseup \ onmouseover onmousemove onmouseout onkeypress \ onkeydown onkeyup onfocus onblur onload \ onunload onsubmit onreset onselect onchange ProxyPass http://xxx.xxx.xxx.120/ ProxyPassReverse http://xxx.xxx.xxx.120/ ProxyHTMLEnable On ProxyHTMLExtended On SetOutputFilter INFLATE;proxy-html;DEFLATE; ProxyHTMLURLMap http://xxx.xxx.xxx.120/ /net </Location> SSLEngine On SSLCertificateFile /etc/letsencrypt/live/myfakedomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/myfakedomain.com/privkey.pem DocumentRoot /var/www/html/myfakedomain <Directory /var/www/html/myfakedomain/> Options Indexes FollowSymLinks MultiViews AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

这是一个非常普遍的问题。 你想代理一些想要在“/”下服务的东西,就好像它在某个其他的URIpath下一样(在这种情况下是/net/ )。

如果底层服务器只发送Location,Content-Location或URI头部redirect,那么你可以使用ProxyPassReverse修复这些,但是如果底层的HTML链接到具有完全限定的URL的资源或URIpath开始“/”,那么你有只有3个真正的select。

  1. 更改底层服务器以在您希望使用的URIpath下提供内容。 (绝对是部署到诸如tomcat等应用服务器的应用程序的最佳select)
  2. 使用Apache v2.4的mod_proxy_html来更正由底层服务器提供的HTML / css / js。
  3. 用mod_sed / mod_substitute将某些东西一起手动修正HTML中的引用。

在第四种select中,您可以尝试重写底层服务器的任何其他URIpath,但是这比上面描述的更为混乱,如果代理多个底层服务的资源,则很less有可能。