[英]Setting up a basic web proxy in apache
I'm looking to run Apache as a proxy for web development. 我希望运行Apache作为Web开发的代理。 I'm running Mac OS X 10.5.4, which already has Apache 2.2.8 installed and running.
我正在运行已安装并运行Apache 2.2.8的Mac OS X 10.5.4。
I'd like to point my JavaScript files (which are running locally on my machine) to: 我想将我的JavaScript文件(在我的机器上本地运行)指向:
http://localhost/test.php
which would hit the local apache server, then have that apache instance forward to my real remote server: 这会打到本地apache服务器,然后将该apache实例转发到我真正的远程服务器:
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://httpd.apache.org/docs/2.0/mod/mod_proxy.html
gives a basic example, but I'm not sure where that text should be added - to http.conf? 给出了一个基本的例子,但我不确定应该在哪里添加文本 - 到http.conf? Do I simply add it there, then restart the server?
我只是将其添加到那里,然后重新启动服务器?
Thanks 谢谢
The proxy setup that you describe is called a Reverse Proxy . 您描述的代理设置称为反向代理 。
This is very easy to set up in Apache, by using the mod_proxy module. 通过使用mod_proxy模块,可以很容易地在Apache中进行设置。
The fundamental mod_proxy directive to set up a reverse proxy is the ProxyPass
. 设置反向代理的基本mod_proxy指令是
ProxyPass
。 You would typically add the following line to your local Apache configuration file (usually httpd.conf
or apache2.conf
): 您通常会将以下行添加到本地Apache配置文件(通常是
httpd.conf
或apache2.conf
):
ProxyPass /remote/ http://www.mysite.com/
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
. 在这种情况下,浏览器将请求
http://localhost/remote/test.php
但您的本地Apache服务器将通过充当http://www.mysite.com/test.php
的代理来提供此服务。
You also need to make sure to have the following configuration lines uncommented in your Apache config file: 您还需要确保在Apache配置文件中取消注释以下配置行:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
Make sure to restart your local Apache service after you do any changes to the config file. 在对配置文件进行任何更改后,请确保重新启动本地Apache服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.