apache 反向代理设置
参考
http://helpful.knobs-dials.com/index.php/Apache_config_and_.htaccess_-_URL_rewriting#Server_redirecting.2Fproxying_.28internal.29
http://shiningray.cn/proxypass-directive-in-apache.html
不能再htaccess中设置proxypass。必须在Context:serverconfig,virtualhost,directory
见
http://stackoverflow.com/questions/12808506/can-proxypass-and-proxypassreverse-work-in-htaccess
如果在htaccess中设置,页面会提示500servererror错误。
且会在error.log中报错,提示“proxpassnotallowinhtaccess”
查看apache错误日志
tail/var/log/apache2/error.log
因此需要到vhost文件中设置。
添加
ProxyRequests Off <Proxy *> Order Deny,Allow Allow from all </Proxy> ProxyPass /log http://ifeng.com ProxyPassReverse /log http://ifeng.com
这样,当域名+/log访问就会显示www.ifeng.com的内容了。
修改了vhost文件必须reload才能生效。
reloadapache命令:
sudo/etc/init.d/apache2reload
在window上试了,但是是直接跳转到ifeng.com。url变了。不知道为什么。同样开启了
proxy,proxy_http的功能。
设置如下
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "E:/wamp/www/it-os-moreversus-cms" ServerName moreversus-cms-local ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common ProxyRequests Off <Proxy *> Order Deny,Allow Allow from all </Proxy> ProxyPass /log http://ifeng.com ProxyPassReverse /log http://ifeng.com </VirtualHost>
也可以不修改vhost,只修改htaccess設置代理。需要給RewriteRule添加[P]proxy的設置。
参考设置
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/abc2014 RewriteRule ^abc2014(.*) http://dev.target.nmg.com.hk/eventId/21$1 [P] # 返回的url用abc2014重定向。因為無eventId的頁面 RewriteCond %{REQUEST_URI} ^/eventId/21 RewriteRule ^eventId/21(.*) abc2014$1 [R] RewriteCond %{REQUEST_URI} ^/Public RewriteRule (.*) http://dev.target.nmg.com.hk/$1 [P] RewriteCond %{REQUEST_URI} ^/Voting RewriteRule (.*) http://dev.target.nmg.com.hk/$1 [P] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(!abc2014|!Public|!Voting)(.*) /index.php [L] </IfModule> # END WordPress
rewriteflag
http://httpd.apache.org/docs/2.2/rewrite/flags.html