External access to API
Modifying Nginx Configuration for External API Access
Section titled “Modifying Nginx Configuration for External API Access”Add the following to nginx.conf
in the server block for the panel domain server_name panel.domen.com;
location ^~ /api/ { proxy_http_version 1.1; proxy_pass http://remnawave; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_send_timeout 60s; proxy_read_timeout 60s;}
This opens access to the API from the outside, while the API will still be protected by an authorization token.
Accessing API through cookies
Section titled “Accessing API through cookies”Acquiring cookie
Section titled “Acquiring cookie”Open nginx.conf and search for map $http_cookie $auth_cookie
. We’ll need the values that go after *
, i.e. for
map $http_cookie $auth_cookie {default 0;"~*aEmFnBcC=WbYWpixX" 1;}
our cookies will be aEmFnBcC=WbYWpixX
.
Sending the cookies in header
Section titled “Sending the cookies in header”Using the HTTP client httpx
and the COOKIES
entry in your project’s .env
file as an example, let’s look at sending cookies in the header:
COOKIES={"aEmFnBcC":"WbYWpixX"}
token = os.getenv("API_TOKEN", "")base_url = os.getenv("REMNAWAVE_BASE_URL", "")cookies = json.loads(os.getenv("COOKIES", "{}"))
async def get_all_nodes(): headers = { "Content-Type": "application/json", "Authorization": "Bearer " + token }
async with httpx.AsyncClient(cookies=cookies) as async_client: response = await async_client.get(f"{base_url}/api/nodes", headers=headers)
return response.json()