Apache Mod-Proxy修改标头为前向代理

发布于 2025-01-24 17:03:50 字数 1056 浏览 4 评论 0原文

我正在使用Apache Server作为代理,以便将一些自定义标头添加到Internet上转发到网站的请求中。我想要像中间的男人一样的阿帕奇。浏览器发送请求,Apache接收到它,添加一些标题,然后Apache将请求转发到原始请求端点。

而不是:

浏览器---> 我想要的网站

浏览器 - > Apache添加标头 - >网站

如何以最简单的方式实现我的目标?

我尝试过作为前向代理,但没有添加标头

<VirtualHost *:*>
   ProxyRequests On
   ProxyVia On
   <Proxy *>
       Require all granted
   </Proxy>
   Header set header "headerValue"
   RequestHeader set header2 "header2value"
</VirtualHost> 

,然后我尝试了反向代理,但是该网站无法加载某些静态资源,因为主机的主机被代理主机覆盖了。

<VirtualHost _default_:82>
    ProxyPreserveHost  Off
    ProxyRequests Off
    ProxyVia On
    ProxyTimeout 300
        <Proxy *>
        Allow from all
        </Proxy>
        ProxyPass /something/something/ http://externalwebsite.com/something/something/
        ProxyPassReverse /something/something/ http://externalwebsite.com/something/something/
        
</VirtualHost>

RequestHeader set header2 "header2value"

你能帮我吗?

非常感谢

i'm using apache server as proxy in order to add some custom headers to the request forwarded to a website on the internet. I want apache like a man in the middle. The browser send a request, apache receives it, it add some headers and then apache forward the request to the original request endpoint.

Instead of:

browser ---> website

I want:

browser --> apache add headers --> website

How can i achieve my goal in the simplest way?

I tried as forward proxy but the header is not added

<VirtualHost *:*>
   ProxyRequests On
   ProxyVia On
   <Proxy *>
       Require all granted
   </Proxy>
   Header set header "headerValue"
   RequestHeader set header2 "header2value"
</VirtualHost> 

then i tried as reverse proxy but the website couldn't load some static resource 'cause the Host header was overrided with the proxy Host.

<VirtualHost _default_:82>
    ProxyPreserveHost  Off
    ProxyRequests Off
    ProxyVia On
    ProxyTimeout 300
        <Proxy *>
        Allow from all
        </Proxy>
        ProxyPass /something/something/ http://externalwebsite.com/something/something/
        ProxyPassReverse /something/something/ http://externalwebsite.com/something/something/
        
</VirtualHost>

RequestHeader set header2 "header2value"

Can you help me pls?

Thank you very much

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文