使用apache作为转发代理并将所有请求重定向到静态页面

发布于 2025-01-06 17:52:57 字数 913 浏览 5 评论 0原文

我尝试将 Apache 设置为代理,它最终会将 JavaScript 文件的请求重写到不同的代码库。我已经设置了 Apache 并充当代理,但无论我做什么,它都不会使用重写规则配置,如下所示。

目前,这一切都在我的本地机器上被毁了。

<VirtualHost *:8000>
RewriteEngine on 
RewriteRule "(.*)" "http://127.0.0.1/test.html" [P]
DocumentRoot "c:/wamp/www/ipvproxy"
ServerName ipvproxy
ProxyRequests On
ProxyVia On
<Proxy *>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Proxy> 

工作配置

<VirtualHost aaa.bbb.ccc.ddd:8000>
   DocumentRoot "c:/wamp/www/"
   CustomLog "c:/wamp/logs/vhost.log" common
   ErrorLog "c:/wamp/logs/vhost_error.log"
   ProxyRequests On
   <Proxy *>
      Order deny,allow
      Deny from all
      Allow from all
   </Proxy>
   RewriteEngine on
   RewriteLog "c:/wamp/logs/rewrite2.log"
   RewriteLogLevel 9
   RewriteRule .* http://127.0.0.1/test.html
</VirtualHost>

I trying to set up Apache as proxy which will eventually rewrite requests for JavaScript files to a different codes base. I have Apache set up and acting as a proxy but no matter what I do it will not use the rewrite rule config is shown below.

Currently this is all ruining on my local machine.

<VirtualHost *:8000>
RewriteEngine on 
RewriteRule "(.*)" "http://127.0.0.1/test.html" [P]
DocumentRoot "c:/wamp/www/ipvproxy"
ServerName ipvproxy
ProxyRequests On
ProxyVia On
<Proxy *>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Proxy> 

Working Config

<VirtualHost aaa.bbb.ccc.ddd:8000>
   DocumentRoot "c:/wamp/www/"
   CustomLog "c:/wamp/logs/vhost.log" common
   ErrorLog "c:/wamp/logs/vhost_error.log"
   ProxyRequests On
   <Proxy *>
      Order deny,allow
      Deny from all
      Allow from all
   </Proxy>
   RewriteEngine on
   RewriteLog "c:/wamp/logs/rewrite2.log"
   RewriteLogLevel 9
   RewriteRule .* http://127.0.0.1/test.html
</VirtualHost>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余厌 2025-01-13 17:52:57

您应该使用反向代理。

类似这样的:

<VirtualHost *:8000>
    DocumentRoot "c:/wamp/www/ipvproxy"
    ServerName ipvproxy

    ProxyPass / http://127.0.0.1/test.html
    ProxyPassReverse / http://127.0.0.1/test.html
</VirtualHost>

然后任何到达 http://ipvproxy:8000 的请求都将被转换为 http://127.0.0.1/test.html

更多信息 此处此处

You should use reverse proxy.

Something like that:

<VirtualHost *:8000>
    DocumentRoot "c:/wamp/www/ipvproxy"
    ServerName ipvproxy

    ProxyPass / http://127.0.0.1/test.html
    ProxyPassReverse / http://127.0.0.1/test.html
</VirtualHost>

Then any request come to http://ipvproxy:8000 will be translated to http://127.0.0.1/test.html

More info here and here

泪是无色的血 2025-01-13 17:52:57

事实证明问题出在我使用的 wampserver 版本上。在 Windown 7 64 位上运行 Wampserver 64 位会出现 mod_rewrite 问题,更改为 wampserver 32 位后一切都开始工作。

It turns out the issue lay with the wampserver version I was using. Running Wampserver 64 bit on Windown 7 64 bit has issues with mod_rewrite, changed to wampserver 32 bit and it all started to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文