Request information from another server

The simplest approach to give make a client get data from another server is to add it in the HTML (link rel for CSS, script src for JS, img src for pictures, AJAX to another server, etc). This makes it a deal between the client and the other server no man in the middle involved (see first part of the picture at the end of the article).

Sometimes the resources are located on single server or on closely bound group of servers. In such cases proxy is also possible approach. One server gets the request then requests the information from another and the initial server sends the data back to the requestor (see second part of the picture at the end).

One option is to use Apache’s proxy module (this fuctionality is available also for the other web servers).

The internet facing server receives the request and silently fetches the resources from another server. The parameters can remain the same or can be also modified. The second server can be IP address or AD PC FQDN or host name or even internet facing address. The basic structure is

ProxyPass /internetVisible http://secondServer
ProxyPassReverse /internetVisible http://secondServer

This is without workers, timeouts, balancers, rewrites, etc. It can get really complicated.

So the above example receives a request for “internetVisible” (or something under this structure) and forwards it to the “secondServer”, gets the results and sends them back to the client. So why not simply request directly from the secondServer? Well.. sometimes the second Server is intentionally not internet facing and only limited set of addresses (options) get exposed to the wide world.

The connection to the secondServer can be performed over HTTP or HTTPS. Without encryption is prefered if the information does not leave the trusted environment and HTTPS can be used to request information over internet.

As shown on the attached picture, there can be several servers in the chain, but the client usually cares only about the first one in the chain.

If the web server functionality is not enough, then external scripts can get involved. For example the server receives request, fetches the data from next server, modifies the data and then sends it back to the requestor. Different scripts can get involved, usually PHP, but sometimes scripts in other languages or even applications get be involved.

Following is an example of PHP script that fetches the data from another server and returns it back:

<?php
   $page=file_get_contents('https://example.com/sensors.php');
   echo $page;
?>

If something has to be replaced the PHP str_replace or some more advanced function/script can be used.

Sometimes the data from multiple servers can be combined and processed to prepare the response to the client.

For example the Home Lab article uses ping to check if the other servers ar up and different text is shown depending on the result. The different PCs are in different frames, that are requested by the client. For the Olimex the request is performed to the DemoAndTest.Website , it forwards it to the single board computer, which runs PHP, which runs sensors and afterwards the data is returned back along the chain.

For the Windows PC it is a little diferent- only the dynamic JSON gets generated on the PC by the Open Hardware Monitor’s web server, then it gets forwarded to the internet facing web server and then to the client. The static files are saved on the web server and are not requested from the Windows PC.

In both cases data, that is not directly accessible from internet is forwarded outside, can be filtered and/or modified at several checkpoints before returning to clients.

Server communication flow
Server communication flow
lia lia lia ... so much fun to add advertisement after the post
Scroll to Top