【问题标题】:Can ProxyPass and ProxyPassReverse work in htaccess?ProxyPass 和 ProxyPassReverse 可以在 htaccess 中工作吗?
【发布时间】:2012-09-30 06:49:48
【问题描述】:

我以前从未设置过代理。我使用的是共享主机,所以要设置 Apache 指令,我需要使用 .htaccess。我可以使用 .htaccess 来执行以下操作吗?有什么限制吗?

ProxyRequests Off
ProxyPass /img/ http://internal.example.com/img/
ProxyPass /app/ http://internal.example.com/app/

ProxyPassReverse / http://internal.example.com/

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    You cannot use a ProxyPass in an htaccess file。文档说它仅适用于上下文:

    上下文:服务器配置、虚拟主机、目录

    不包括 htaccess(你不能在 htaccess 中有 <Directory> 块)。但是,您可以使用 ProxyPassReverse 在内部重写导致重定向的代理请求的 Location 字段。您只需要使用 mod_rewrite 的 P 标志来代理而不是 ProxyPass。所以像:

    RewriteEngine On
    RewriteRule ^/?img/(.*)$ http://internal.example.com/img/$1 [L,P]
    RewriteRule ^/?app/(.*)$ http://internal.example.com/app/$1 [L,P]
    
    ProxyPassReverse / http://internal.example.com/
    

    为了清楚起见,您不能在 htaccess 文件中使用 ProxyPass ProxyPassReverse,但您可以ProxyPassReverse 与 mod_rewrite 规则一起使用P 标志。

    【讨论】:

    • 你也不能在 htaccess 中使用ProxyPassReverse (httpd.apache.org/docs/current/mod/…)
    • 当我在 OSX Server 3.1.1 的 htaccess 中使用 ProxyPassReverse 时,我收到以下“ProxyPassReverse not allowed here”
    • 我在 OSX 10.9 上,而且这里也不允许使用 ProxyPassReverse。
    • 我在 .htaccess 中使用它来修复重定向:Header edit Location ^http://internal\.example\.com/(.*) http://example.com/$1
    • 我被困在试图让代理工作好几天了,但这真的很有帮助。最后不需要ProxyPassReverse / http://internal.example.com/ 部分
    猜你喜欢
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 2012-10-07
    • 2013-03-02
    • 2012-09-19
    • 2011-12-10
    相关资源
    最近更新 更多