.htaccess ProxyPass和ProxyPassReverse可以在htaccess中工作吗?

q9yhzks0  于 2022-12-13  发布在  其他
关注(0)|答案(2)|浏览(112)

我以前从来没有设置过代理。我使用的是共享主机,所以要设置Apache指令,我需要使用. htaccess。我可以使用.htaccess来做下面的事情吗?有什么限制吗?

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

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

mlmc2os51#

You cannot use a ProxyPass in an htaccess file. The documentation says it is only applicable in the context:
Context: server config, virtual host, directory
which excludes htaccess (you can't have a <Directory> block in htaccess). However, you can use a ProxyPassReverse to internally rewrite the Location field of proxied requests that cause a redirect. You'll just need to use mod_rewrite's P flag to proxy instead of ProxyPass . So something like:

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/

Just to be clear, you cannot use ProxyPassorProxyPassReverse in the htaccess file, but you can use ProxyPassReverse with mod_rewrite rules that utilize the P flag.

8i9zcol2

8i9zcol22#

您不能使用ProxyPassReverse,但是如果您能够在HTML从源服务器返回时重写它,则可以模仿它。
请看我的文章here

相关问题