<@ULVA73B9P> when self-hosting prefect, is there a...
# marvin-in-the-wild
s
@Marvin when self-hosting prefect, is there a way to change the path where the api runs? From what I can tell, it always runs at {host}/api. Is there a way to change it to run at {host}/{path}/api, similar to how you can use PREFECT_UI_SERVE_BASE to specify the path for the UI?
m
It seems there's no direct documentation indicating the possibility of changing the API endpoint path in a self-hosted Prefect installation like you can with
PREFECT_UI_SERVE_BASE
for the UI. The default base path for the API is
<http://127.0.0.1:4200/api>
. However, you can work around this by using a reverse proxy (such as Nginx or Traefik) to achieve the desired routing. With the right configuration, the proxy server can forward requests from your custom path to the default Prefect API path. Here's a general approach using Nginx: 1. Install Nginx:
Copy code
bash
   sudo apt update
   sudo apt install nginx
2. Configure Nginx for your custom path: Edit your Nginx configuration file to include the following:
Copy code
nginx
   server {
       listen 80;
       server_name your_domain_or_ip;

       location /custom_path/api {
           proxy_pass <http://127.0.0.1:4200/api;>
           proxy_set_header Host $host;
           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;
       }
   }
Replace
/custom_path/api
with your preferred path and
your_domain_or_ip
with your server's domain or IP address. 3. Restart Nginx:
Copy code
bash
   sudo systemctl restart nginx
With this setup, requests to
{host}/custom_path/api
will be forwarded to the Prefect API running at
{host}/api
. --- References: - Prefect Hosting Guide - Prefect Settings Guidance For more detailed configurations, please refer to the Nginx documentation.