简体   繁体   English

关于开发RETS PHP隧道的建议

[英]Suggestion on developing a RETS PHP Tunnel

I have partially developed a property website that fetch properties data from a RETS IDX. 我已经部分开发了一个房地产网站,该网站可以从RETS IDX获取房地产数据。 You may know that RETS server listened to port 6103 over http protocol. 您可能知道RETS服务器通过http协议监听了端口6103。 My website is deployed on a shared hosting due to which I can not connect to 6103 port. 由于无法连接到6103端口,我的网站部署在共享主机上。 I do have a dedicated server (which allows connect to port 6103). 我确实有专用服务器(允许连接到端口6103)。 I want to use this dedicated server as a middle tier between my website and the RETS IDX server. 我想将此专用服务器用作我的网站和RETS IDX服务器之间的中间层。 My problem is I want to develop that middle tier script ie HTTP Tunnel. 我的问题是我想开发中间层脚本,即HTTP隧道。

My website will send all RETS request to this Tunnel that will meanwhile sent it to the RETS IDX server and its response will be sent back to the website at the same moment. 我的网站会将所有RETS请求发送到此隧道,同时将其发送到RETS IDX服务器,并且其响应将同时发送回网站。

                         port 80                                 port 6103

Website (shared hosting) ----------> Tunnel (Dedicated hosting)  -----------> RETS Server

RETS Server also requires to login, so the session should be maintained properly. RETS Server也需要登录,因此会话应得到正确维护。

I want to have quick/best solution to do the job. 我想有快速/最佳的解决方案来完成这项工作。 May be through .htaccess or streaming php script or may be some third party script can also cut some of my time. 可能通过.htaccess或流式传输php脚本,或者某些第三方脚本也可以节省一些时间。

I would love to hear any thought or suggestion you have. 我很想听听您的任何想法或建议。

PS: I can not move my website to a dedicated server because in near future I am going to have plenty of them and they would cost too much. PS:我不能将网站移到专用服务器上,因为在不久的将来,我将拥有很多服务器,而且它们的成本太高了。

I'd personally go for the Reverse Proxy approach. 我个人将使用反向代理方法。 This will allow you to intelligently forward requests, based on configurable criteria. 这将允许您根据可配置的标准智能地转发请求。

Both Apache and nginx have reverse proxy capabilities (in fact it was nginx's original purpose). Apache和nginx都具有反向代理功能(实际上,这是nginx的初衷)。 For Apache you need to use mod_proxy , while nginx has the functionality built in unless you explicitly disable it before compiling. 对于Apache,您需要使用mod_proxy ,而nginx具有内置功能,除非您在编译前明确禁用了该功能。

Of these two options I personally prefer nginx, it is robust and lightweight, and completely fit for purpose. 在这两个选项中,我个人更喜欢nginx,它既坚固又轻巧,完全适合特定目的。 I find Apache more cumbersome, but if you already have Apache set up on your dedicated server, you may prefer to use that instead. 我发现Apache麻烦一些,但是如果您已经在专用服务器上设置了Apache,则最好使用它。

The beauty of using web servers to proxy, is that they understand the underlying protocol . 使用Web服务器进行代理的美妙之处在于它们了解底层协议 They will preserve headers, modify cookies (preserve sessions), and translate hostnames correctly. 它们将保留标题,修改Cookie(保留会话)并正确转换主机名。


Apache Config Apache配置

In both cases configuration is very straightforward, the Apache config looks something like the following: 在这两种情况下,配置都非常简单,Apache的配置如下所示:

 <Location /proxy-location/> ProxyPass /rets http://rets-server:6103/api/path ProxyPassReverse /rets http://rets-server:6103/api/path </Location> 

There's also options for tweaking cookies, setting timeouts etc. All of which can be found in the mod_proxy documentation 还有用于调整Cookie,设置超时等的选项。所有这些都可以在mod_proxy文档中找到。

You should note that this cannot go in a .htaccess file. 您应该注意,这不能放在.htaccess文件中。 It must go in the main server config. 它必须进入主服务器配置。


nginx Config Nginx的配置

Equally as simple 同样简单

 location /proxy-location { proxy_pass http://rets-server:6103/api/path; } 

Again tons of options in the HttpProxyModule documentation for caching, rewriting urls, adding headers etc. HttpProxyModule文档又有很多选项用于缓存,重写url,添加标头等


Please do consult the docs. 内容参考文档。 I've not tested either of these configurations and they may be a little off as they're from memory + a quick google. 我没有测试过这些配置中的任何一个,它们可能有点不足,因为它们来自内存+快速的Google。

Make sure you test your app by proxying to an unreachable server and ensure it handles failures correctly since you are introducing another point of failure. 确保通过代理不可达的服务器来测试您的应用程序,并确保它可以正确处理故障,因为您引入另一个故障点。

I'm working on the assumption you are able to configure your own dedicated server. 我正在假设您能够配置自己的专用服务器。 If this is not the case, your hosts may be willing to help you out. 如果不是这种情况,您的房东可能愿意帮助您。 If not leave me a comment and I'll try and come up with a more robust curl option. 如果没有给我留下任何评论,我将尝试并提出一个更强大的curl选项。

You can achieve this by using curl's PHP extension. 您可以使用curl的PHP扩展来实现。

An example code could be : 示例代码可能是:

$url = $_GET['url'];

$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$content = curl_exec($ch);

echo $content;

Obviously you have to add protection, perhaps add .htaccess/.htpasswrd protection to it. 显然,您必须添加保护,或者为其添加.htaccess / .htpasswrd保护。

A more complete code, with cookie support and such, can be found there : https://github.com/cowboy/php-simple-proxy 可以在此处找到具有cookie支持等功能的更完整的代码: https : //github.com/cowboy/php-simple-proxy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM