nginx - How can I remotely access a localhost application running on a Windows Server using PHP?

We are using Paxton Software and that is running on a Windows Server. The Windows Server is hosted and accessible by both a domain name (winserver.domain.com) and IP-address.

On the Windows Server, Paxton Software is running and they have a Web API (REST) using nginx. We can call the API on the Windows Server by using localhost:8080 as hostname (using RDP). So far, so good.

Now, we would like to create a PHP application that is connecting to multiple Web API's of Paxton. Basically, it should connect to multiple Windows Servers and it should be possible to call the API endpoint.

What we've tried: We tried to use CURL to do a request to the windows server. We tried to setup a proxy to the IP-address:3389 (that's the port RDP is using), using a PROXYUSERPWD to login. Sadly, that didn't work, because of the following error: Recv failure: Connection was reset. The script:

$url = 'http://localhost:8080/webapihelp/';
$proxy = 'http://0.0.0.0:3389';
$proxyauth = 'username123:password456';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curlResponse = curl_exec($ch);
var_dump(curl_error($ch));
curl_close($ch);

Is it possible to connect to the Windows Server directly? If not, what do we need in order to achieve that goal?

Answer

Solution:

There are plenty of options to do so.

  1. You might be able to configure your server software to have it listen on a public port;
  2. Use netsh to forward a public port on the server running Paxton Software . The "listenaddress" will be your Server's network address, and connectaddres will be localhost. netsh interface portproxy add v4tov4 listenaddress=localaddress listenport=localport connectaddress=destaddress connectport=destport
  3. Install an SSH server on your Windows server, and add tunnel(s) to your windows server(s) from the server running the PHP application.
    It is safer because only your PHP server will be able to access the local port.
    I've used 'autossh' in the past to make sure that the tunnel remains open.
    You can forward ports directly from the client host (network) to the server host (network) and the other way around. Examine the '-R' and '-L' options of ssh.
  4. Use rdp2tcp - Never used it, but it works specifically with RDP to forward TCP ports.

Source