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: server config, virtual host, directory


http://stackoverflow.com/questions/12808506/can-proxypass-and-proxypassreverse-work-in-htaccess

如果在htaccess中设置,页面会提示500 server error错误。
且会在error.log中报错,提示“proxpass not allow in htaccess”

查看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才能生效。

reload apache命令:
sudo /etc/init.d/apache2 reload

在window上试了,但是是直接跳转到ifeng.com。url变了。不知道为什么。同样开启了
proxy,proxy_http的功能。
设置如下

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
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


rewrite flag
http://httpd.apache.org/docs/2.2/rewrite/flags.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值