API request ends with 301 localhost

Hi,

here my config snippet to use the API.

I have attached my curl command also.
The Curl command snipped is copied from the latest docu

set service https api keys id vyos key ‘key’
set service https api port ‘443’
set service https certificates certificate ‘vyostest’
set service https virtual-host vyos listen-address ‘*’

Vyos Version

Built on: Fri 17 Mar 2023 03:17 UTC

PS C:\> curl.exe -k --location --request POST 'https://10.10.0.144/retrieve' --form data='{"op": "showConfig", "path": []}'  --form key='key' -vvv
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 10.10.0.144:443...
* Connected to 10.10.0.144 (10.10.0.144) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: using IP address, SNI is not supported by OS.
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> POST /retrieve HTTP/1.1
> Host: 10.10.0.144
> User-Agent: curl/7.83.1
> Accept: */*
> Content-Length: 282
> Content-Type: multipart/form-data; boundary=------------------------029298edb7fada03
>
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.22.1
< Date: Thu, 30 Mar 2023 13:43:10 GMT
< Content-Type: text/html
< Content-Length: 169
< Connection: keep-alive
< Location: https://localhost:443/retrieve
<
* Ignoring the response-body
* Connection #0 to host 10.10.0.144 left intact
* Issue another request to this URL: 'https://localhost:443/retrieve'
* Switch from POST to GET
*   Trying 127.0.0.1:443...
*   Trying ::1:443...
* connect to 127.0.0.1 port 443 failed: Connection refused
* connect to ::1 port 443 failed: Connection refused
* Failed to connect to localhost port 443 after 1228 ms: Connection refused
* Closing connection 1
curl: (7) Failed to connect to localhost port 443 after 1228 ms: Connection refused
PS C:\>




Change IP to domain name. Since the nginx only work with domain as a revese proxy server. With only IP address, Nginx can’t redirect your request to api serivice.

1 Like