在 apache 中设置基本的 Web 代理 [英] Setting up a basic web proxy in apache
问题描述
我希望将 Apache 作为 Web 开发的代理运行.我正在运行 Mac OS X 10.5.4,它已经安装并运行了 Apache 2.2.8.
I'm looking to run Apache as a proxy for web development. I'm running Mac OS X 10.5.4, which already has Apache 2.2.8 installed and running.
我想将我的 JavaScript 文件(在我的机器上本地运行)指向:
I'd like to point my JavaScript files (which are running locally on my machine) to:
http://localhost/test.php
这将访问本地 apache 服务器,然后将该 apache 实例转发到我真正的远程服务器:
which would hit the local apache server, then have that apache instance forward to my real remote server:
http://www.mysite.com/test.php
我看过一些演练,但它们似乎已经过时.我想知道是否有最近的设置方法 - 此处的文档:
I've looked at a few walkthroughs but they seem to be out of date. I'm wondering if there's a recent how-to on setting this up - the doc here:
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
给出了一个基本示例,但我不确定应该将文本添加到何处 - 到 http.conf?我是否只需将它添加到那里,然后重新启动服务器?
gives a basic example, but I'm not sure where that text should be added - to http.conf? Do I simply add it there, then restart the server?
谢谢
推荐答案
您描述的代理设置称为 反向代理.
The proxy setup that you describe is called a Reverse Proxy.
通过使用mod_proxy>模块.
设置反向代理的基本 mod_proxy 指令是 ProxyPass
.您通常会将以下行添加到本地 Apache 配置文件(通常是 httpd.conf
或 apache2.conf
):
The fundamental mod_proxy directive to set up a reverse proxy is the ProxyPass
. You would typically add the following line to your local Apache configuration file (usually httpd.conf
or apache2.conf
):
ProxyPass /remote/ http://www.mysite.com/
在这种情况下,浏览器将请求 http://localhost/remote/test.php
但您的本地 Apache 服务器将通过充当 http:/的代理来提供服务/www.mysite.com/test.php
.
In this case, the browser would be requesting http://localhost/remote/test.php
but your local Apache server would serve this by acting as a proxy to http://www.mysite.com/test.php
.
您还需要确保在 Apache 配置文件中取消注释以下配置行:
You also need to make sure to have the following configuration lines uncommented in your Apache config file:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
确保在对配置文件进行任何更改后重新启动本地 Apache 服务.
Make sure to restart your local Apache service after you do any changes to the config file.
这篇关于在 apache 中设置基本的 Web 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!