我想要一个可以“转发”的代理服务器到两个开发服务器
摘要:
所有开发都在我的本地计算机上进行。我的机器上运行着两台开发服务器。我想像使用这些开发服务器一样使用它们。最简单的方法是什么?
详细信息
我有两台开发服务器。一台服务器是 Sproutcore 开发服务器(保存应用程序、CSS、图像等)。另一台服务器是 App Engine 开发服务器(保存数据)。 App Engine 服务器的访问方式是有限的。这两个开发服务器都在我的计算机上的不同端口上运行。
假设我有一个名为 X 的正则表达式,它指定可用于访问应用程序引擎服务器的所有 url 路径。
我想要一个代理服务器,它将所有与 X 匹配的 http 请求路径转发到 App Engine 服务器,并将所有不匹配的路径转发到 Sproutcore 服务器。
示例:
如果我的代理服务器是localhost:8080
我的应用程序引擎服务器是localhost:8081
我的 sproutcore 服务器是 localhost:8082
我有一个与“/dogs/_the_dogs_id”匹配的正则表达式(其中_the_dogs_id是一个整数)
如果我发出localhost:8080/js/application.js的请求,我希望它会转到sproutcore服务器(因为它不匹配正则表达式)
如果我发出localhost:8080/dogs/7的请求,我希望它转到应用程序引擎服务器(因为它确实匹配正则表达式)
就我的(客户端)请求而言,我只向 localhost:8080 询问所有这些资源。代理服务器正在默默地将它们转发到正确的目的地。保留请求类型、数据、标头等。我只需要它根据 url 请求路径转发它。
有什么简单的方法来设置这样的代理服务器吗?这对于网络开发非常有用。
谢谢
Summary:
All development is on my local machine. I have two development servers running on my machine. I would like to use these development servers as if they were one. What is the simplest way to do this?
Details
I have two development servers. One server is the Sproutcore development server (holds the application, css, images, whatever). The other server is the App Engine development server (holds the data). The app engine server has a finite number of ways that it can be accessed. Both of these development servers are running on separate ports on my machine.
Lets say I have a regular expression called X that specifies all the url paths that can be used to access the app engine server.
I would like a proxy server that will forward all http request paths matching X to the App Engine server, and all non matching paths to the Sproutcore server.
Example:
If my proxy server is localhost:8080
And my app engine server is localhost:8081
And my sproutcore server is localhost:8082
And I have a regular expression that matches "/dogs/_the_dogs_id" (where _the_dogs_id is a integer)
If I make a request of localhost:8080/js/application.js I would expect that to go to the sproutcore server (because it does not match the regular expression)
If I make a request of localhost:8080/dogs/7 I would expect that to go to the app engine server (because it does match the regular expression)
As near as my (the client) request is concerned, I am only asking localhost:8080 for all these resources. The proxy server is silently forwarding them to the correct destination. Preserving the request type, the data, the headers, etc. I just need it to forward it based on the url request path.
Is there any simple way to set up such a proxy server? It would be immensly useful for web development.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mod_rewrite
FTWhttp://httpd.apache.org/文档/current/mod/mod_rewrite.html
您定义一个与 URL 匹配的正则表达式,然后将其重写到您想要将请求重定向到的位置。
另外,为了澄清,您描述的机制称为“反向代理”: http://en.wikipedia .org/wiki/Reverse_proxy
-tjw
mod_rewrite
FTWhttp://httpd.apache.org/docs/current/mod/mod_rewrite.html
You define a regular expression that matches a URL, and then re-writes it to where you want to re-direct the request to.
Also, to clarify, the mechanism you are describing is called a "Reverse Proxy": http://en.wikipedia.org/wiki/Reverse_proxy
-tjw
事实上,经过进一步调查,发现 Sproutcore 具有内置功能来完成这件事。他们提前思考这些问题的方式令人印象深刻。将代理添加到特定路由就像在“# SET UP PROXY”注释(在您的构建文件中)下面添加以下几行一样简单,
真的再简单不过了。我也非常喜欢它,因为它是一个便携式解决方案。这与需要其他依赖项的解决方案(例如 Apache)形成鲜明对比。
Actually, upon further investigation, it turns out that Sproutcore comes with built in functionality to do this exact thing. Just really impressive how they think of these thinks ahead of time. Adding a proxy to a particular route is as easy as adding the following lines below the "# SET UP PROXY" comment (In your Buildfile)
Really could not be much simpler. I also like this a great deal because it is a portable solution. This contrast to solutions requiring another depency (eg. Apache).