我们目前正在将我们的网站迁移到CMS,并且正在转移到另一台服务器。 旧服务器上有一些代码,我们不想移动到新的服务器上。 我们希望url是相同的,所以我们一直在看(现在正在使用)ProxyPass。 旧服务器实际上是将URL重新映射到公共和内部内容。 旧服务器上的<Proxy>指令仍然被注释掉,并且工作正常。
我已经尝试将以下几个地方放在一个虚拟主机指令之内,在它之外等,我没有错误启动apache,但它永远不会工作。
ProxyRequests On Order allow,deny Allow from all ProxyVia On ProxyPreserveHost On ProxyPass /tester/ http://oldserver.companyname.com/app1/ ProxyPassReverse /tester/ http://oldserver.companyname.com/app1/
我已经尝试过几个例子,比这更简单了,等等。
Apache似乎忽略了tester ,并将其发送到CMS,然后返回404。我们希望testing人员掩盖旧的URL,这是我们目前在其他计算机上执行的操作。
这个特定的虚拟主机确实有一些重写规则,我也试过在之前或之后放置这些规则。 这些模块在httpd.conf中被加载。 目前运行的Apache 2.2。
现在 – 没有任何反应。 没有错误,没有日志(我看到)等等。这就像规则实际上并不存在。
有一件事我注意到了 – 它在我们的其他虚拟主机指令中工作正常。 唯一的区别是另一个是小得多,并不包含一些重写Wordpress的规则。
这里是我的VirtualHost的一个例子
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/wordpress ServerName wptest ServerAlias wptest.site.com.local ErrorLog /var/log/httpd/wordpress-error-log CustomLog /var/log/httpd/wordpress-access-log common ProxyPass /tester http://www.company.com/app1 RewriteEngine On <IfModule mod_rewrite.c> #RewriteBase /wordpress/ # Switched the logging on 2/15/13 JMD RewriteLog "/var/log/httpd/rewrite_log" RewriteLogLevel 4 # From https://stackoverflow.com/questions/13235180/how-to-remove-trailing-slash-for-folder-index-html-when-index-html-is-stri # If it's a request to index(.html) RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC] # Remove it. RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L] RewriteCond %{REQUEST_URI} \.html$ RewriteRule ^(.*)\.html$ $1 [R=301,L] RewriteRule ^/index\.php$ - [L] RewriteRule ^/css/(.*) /wp-content/themes/our2012/css/$1 [QSA,L] RewriteRule ^/js/(.*) /wp-content/themes/our2012/js/$1 [QSA,L] RewriteRule ^/img/(.*) /wp-content/themes/our2012/img/$1 [QSA,L] RewriteRule ^/font/(.*) /wp-content/themes/our2012/font/$1 [QSA,L] RewriteRule ^/plugins/(.*) /wp-content/plugins/$1 [QSA,L] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> </VirtualHost>
( 每个请求从StackOverflow交叉 )
如果您的CMS使用Mod在.htaccess中重写,可能会在proxypass之前处理domain.com/test。
你可能会考虑的是使用带有[p]标志的重写规则以及wordpress重写规则。
(未经检验的规则很快就以一个例子为例)
RewriteRule /test/$ http://oldserver.example.com/ [P] ProxyPassReverse /test/ http://oldserver.example.com/
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
另一个关于使用mod_rewrite到Proxy的信息的链接
http://httpd.apache.org/docs/2.2/rewrite/proxy.html