我目前有一个运行 Apache 2.4.x 的 Ubuntu 系统,它与其他一些 Windows 服务器在单个 IP 环境中运行。因此,我目前已将 Apache 配置为以反向代理(例如 Exchange)的形式处理某些域请求。
到目前为止,我已经设法让 VirtualHost 使用适当的证书等连接到后端系统。但最近我去查看了 Apache 机器上的连接日志,因为我注意到后端网站上有些图像没有加载。我当前的配置似乎是在每个请求上添加反向代理子文件夹(见下面的日志)。
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/assets/script/webConsole.js HTTP/1.1" 302 730
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/loginwebconsole/assets/script/webConsole.js HTTP/1.1" 302 762
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/loginwebconsole/loginwebconsole/assets/script/webConsole.js HTTP/1.1" 302 794
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/loginwebconsole/loginwebconsole/loginwebconsole/assets/script/webConsole.js HTTP/1.1" 302 826
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/loginwebconsole/loginwebconsole/loginwebconsole/loginwebconsole/assets/script/webConsole.js HTTP/1.1" 302 858
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/loginwebconsole/loginwebconsole/loginwebconsole/loginwebconsole/loginwebconsole/assets/script/webConsole.js HTTP/1.1" 302 890
XXX.XXX.XXX.XXX - - [26/Nov/2013:16:24:13 +0100] "GET /webconsole/loginwebconsole/loginwebconsole/loginwebconsole/loginwebconsole/loginwebconsole/loginwebconsole/assets/script/webConsole.js HTTP/1.1" 302 922
我当前的 httpd.conf
DocumentRoot /var/www/xxxxx.xxxxxx.com
ServerName xxxxx.xxxxxx.com
ProxyPreserveHost On
ProxyVia Full
RequestHeader edit Transfer-Encoding Chunked chunked early
RequestHeader unset Accept-Encoding
ProxyRequests Off
TimeOut 1800
SSLEngine on
SSLProxyEngine On
SSLCertificateFile /var/www/xxxx.xxxxx.xxx/xxxx/xxxxx.crt
SSLCertificateKeyFile /var/www/xxxx.xxxxx.xxx/xxxx/xxxxx.key
Redirect / https:// xxxx.xxxxx.com /webconsole/login (space because topic see as url)
<Location /webconsole/login>
ProxyPass https:// xxxx.xxxxx.com /webconsole/login (space because topic see as url)
ProxyPassReverse https:// xxxx.xxxxx.com /webconsole/login (space because topic see as url)
SSLRequireSSL
</Location>
ErrorLog /var/log/apache2/xxxx_xxxxx_errorlog
CustomLog /var/log/apache2/xxxx_xxxxx_com common
我似乎不明白为什么会发生这种情况或如何解决这个问题。
答案1
不要使用Redirect
指令。只需ProxyPass
这样ProxyPassReverse
就足够了。
以下对我有用。
ProxyRequests 关闭 ProxyPass /myapp/path http://后端主机:端口/myapp/path ProxyPassReverse /myapp/path http://后端主机:端口/myapp/path
我通常会尝试使代理上公开的绝对路径与后端服务器中的绝对路径保持相同,以避免出现明确重定向的应用程序问题。
编辑:这是我的 ubuntu 10.04 上的完整虚拟主机配置。
<VirtualHost *:80>
DocumentRoot /home/b/public_html
ServerName a.b.com
ServerAlias a.b.com
ErrorLog /var/log/apache2/a.b.com-error.log
CustomLog /var/log/apache2/a.b.com-access.log common
ProxyRequests Off
ProxyPass /myapp/path http://backend-host:port/myapp/path
ProxyPassReverse /myapp/path http://backend-host:port/myapp/path
</VirtualHost>