Apache:将子文件夹redirect到局域网中的另一个IP

我有webserver1后面的路由器当前服务所有http通信到mydomain.com。 我刚刚添加了webserver2,并希望将mydomain.com/server2stream量redirect到该框。 对用户来说,redirect应该是不被注意的(即,URL应该是mydomain.com/server2,而redirect是在幕后发生的)。 我如何设置这个在web服务器1的Apacheconfiguration(我假设web服务器2的configuration需要做什么特别)?

我已经尝试了这里给出的build议,使用mod_rewrite,但它似乎并没有这样做:

RewriteEngine on RewriteCond %{REQUEST_URI} ^/server2/ RewriteRule ^/$ http://192.168.1.102/ [P,L] 

万一它是相关的,webserver1正在主持一个使用mod_wsgi的django应用程序,其他一些应用程序被redirect。 这是virtualhost conf:

 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.mydomain.com ServerAlias 127.0.0.1 RewriteEngine on RewriteCond %{REQUEST_URI} ^/server2/ RewriteRule ^/$ http://192.168.1.102 [P,L] DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> <Directory /var/www/mydomain> Order allow,deny Allow from all </Directory> ... WSGIDaemonProcess mydomain user=user group=user threads=25 WSGIProcessGroup mydomain WSGIScriptAlias / /home/user/mydomain/apache/django.wsgi Alias /phpmyadmin /usr/share/phpmyadmin/ </VirtualHost> 

提前致谢。

Mod_Rewrite比mod_proxy更灵活。 取消它的负载线的注释。

简单比较这里http://www.wellho.net/mouth/1376_Choosing-between-mod-proxy-and-mod-rewrite.html

 <VirtualHost *:80> RewriteEngine on # just in case (don't want to accidentally expose all the internal servers) ! ProxyRequests off # define a log file RewriteLog /var/log/apache/server2.rewrite.log RewriteLogLevel 1 # add the tailing / if not there RewriteRule ^/server2$ http://www.mydomain.com/server2/ [R] [L] # proxy the request to internal url RewriteRule ^/server2/(.*) http://192.168.1.102/$1 [P] 

请注意,这个例子是区分大小写的。

使用:

 ProxyPass /server2 http://192.168.1.102/server2 

您也可能需要ProxyPassReverse。 请参阅Apache文档:

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass

请注意,后端mod_wsgi必须将应用程序安装在与前端出现和被代理的URL相同的子URL上。

另外请注意,可能需要在后端进行configuration以摆脱出现的后端应用程序正在运行的主机/端口,因此后端的URL重构在使用时会正常工作。 所以研究,如果你发现这是一个问题。