Я пытаюсь перенаправить / net для myfakedomain.com на другой ip xxx. xxx.xxx.120 в локальной сети.
То есть, когда я пытаюсь получить доступ к myfakedomain.com/net, он должен показать содержимое xxx.xxx.xxx.120
, я также перенаправляю HTTP-запросы на 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, e.g.
#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, e.g.
#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 not found .
Я пробовал использовать 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
Это очень распространенная проблема. Вы хотите проксировать что-то, что хочет обслуживаться под '/', как если бы оно находилось под каким-то другим путем URI (в данном случае /net/
).
Если основной сервер когда-либо отправлял только Location, Content-Location или перенаправление заголовка URI, то вы можете исправить это с помощью ProxyPassReverse
, но если основной HTML имеет ссылки на ресурсы либо с полными URL, либо с путями URI, которые начинаются с '/', то у вас есть только 3 реальных варианта.
Есть 4-й вариант, где можно попробовать переписать любые другие пути URI, которые обслуживаются базовым сервером, но это еще более запутанно, чем описано выше, и это редко возможно, если вы проксируете ресурсы более чем одного базового сервиса.
.