Use the Add Domain Forwarding Record API to add domain forwarding record for the vps present on your server by passing the VPS UUID to the API. The VPS UUID can be obtained from the List Virtual Server API where you can filter the list by passing the VPS name/ VPS ID.
The API response will contain "done" as "ID" of the newly added record.
VPS Domain Forwarding feature in Virtualizor allows VPSes to host HTTP/HTTPS services or any other TCP services on a private IP without any need for a public IP. To host an HTTP/HTTPS service, all that is required for a VPS is a valid domain name registered with any Domain Registrar. This domain name must point to any one of the source IPs made available for VPS Domain Forwarding by Virtualizor administrator.
For more information you can refer this Manage VPS Domain Forwarding Guide.
HTTP Request
https://hostname:4085/index.php?act=haproxy
Parameters
Name | Method | Value | Description | Required |
---|---|---|---|---|
act | GET | haproxy | The action specified to carry out operation and return data | Yes |
serid | POST | Int | The ID of the server | Yes |
vpsuuid | POST | text | The uuid of the vps | Yes |
protocol | POST | text | The protocol for the domain forwarding can be (HTTP, HTTPS, TCP) | Yes |
src_hostname | POST | text | The source hostname can be IP | Yes |
src_port | POST | text | The source port | Yes |
dest_ip | POST | text | The destination IP of the vps | Yes |
dest_port | POST | text | The destination port of the vps | Yes |
action | POST | text | The action to be performed should be 'addvdf' | Yes |
Sample Code
<?php
require_once('/usr/local/virtualizor/sdk/admin.php');
$key = 'your_api_key';
$pass = 'your_api_pass';
$ip = 'your_server_ip';
$admin = new Virtualizor_Admin_API($ip, $key, $pass);
$post = array();
$post['serid'] = 0;
$post['vpsuuid'] = 'VPSUUID';
$post['protocol'] = 'TCP';
$post['src_hostname'] = '202.168.147.144';
$post['src_port'] = 1224;
$post['dest_ip'] = '10.0.0.10';
$post['dest_port'] = 22;
$post['action'] = 'addvdf';
$output = $admin->haproxy($post);
print_r(json_encode($output));
?>
Output
{
"title": "VPS Domain Forwarding",
"done": {
"msg": "Added successfuly\n",
"id": "3"
},
"haproxydata": {
"2": {
"id": "2",
"vpsuuid": "tfri5lvqzl8lqhvt",
"serid": "0",
"protocol": "TCP",
"src_hostname": "202.168.147.144",
"src_port": "4545",
"dest_ip": "10.0.0.10",
"dest_port": "22",
"timeadded": "1535462225",
"timeupdated": "0",
"skipped": "",
"vpsid": "62",
"vps_name": "v1016",
"hostname": "www.mydomain.com"
},
"3": {
"id": "3",
"vpsuuid": "tfri5lvqzl8lqhvt",
"serid": "0",
"protocol": "TCP",
"src_hostname": "202.168.147.144",
"src_port": "1224",
"dest_ip": "10.0.0.10",
"dest_port": "22",
"timeadded": "1535467331",
"timeupdated": "0",
"skipped": "",
"vpsid": "62",
"vps_name": "v1016",
"hostname": "www.mydomain.com"
}
},
"supported_protocols": [
"HTTP",
"HTTPS",
"TCP"
],
"server_haconfigs": [
{
"haproxy_src_ips": "202.168.147.144",
"haproxy_reservedports": "",
"haproxy_reservedports_http": "80,443",
"haproxy_allowedports": ""
}
],
"vpsips": null,
"timenow": 1535467331,
"time_taken": "0.266"
}