Hi folks -- I think I know the answer to this, but...
# ask-community
h
Hi folks -- I think I know the answer to this, but is it currently unsupported to run Prefect Server behind a reverse proxy with a prefixed path -- e.g. https://example.com/prefect ? I see a number of bugs and some proposed MRs, but looks like everything has been closed as "won't fix" / "too complicated" and, indeed, I seem unable to get this working locally.
πŸ‘€ 1
βœ… 1
i
Hi Hans, Yes it's possible, you just need to set two env variables accordingly as mentioned here: https://docs.prefect.io/latest/guides/settings/#:~:text=Running%20the%20Prefect%20UI%20behind%20a%20reverse%20proxy
h
Ok, yes, I have read that (and I actually wrote the original PR for that reverse proxy section). I will try again, but this was not working for me. I can run Prefect behind a reverse proxy, but not change the path from / to something else -- e.g. /prefect. But if this should work, I will try again.
So, the naively doing:
Copy code
location /prefect/ {
    include proxy_params;  # Header, etc.
    proxy_pass <http://prefect-server:4200>;
}
with compose service like
Copy code
prefect-server:
    # snip
    entrypoint: [ "prefect", "server", "start" ]
    environment:
      # Instruct the JS UI how to connect to the UI server
      - PREFECT_UI_API_URL=<https://localhost/prefect/api>
      - PREFECT_SERVER_API_HOST=0.0.0.0
does not work. prefect still expecting to find resources at root.
How do I tell Prefect the URL path it should use for its UI resources?
πŸ‘€ 1
i
I apologize I was wrong about this, and you're right. After looking into it deeper, we seem to have a warning for not having
/api
after the base URL. I did get a working scenario, with an nginx config like yours, and I set these two vars like so (ports/remote-host adapted to your example):
Copy code
PREFECT_API_URL='<http://localhost/prefect/api>'
PREFECT_UI_API_URL='<http://localhost/prefect/api>' (from profile)
The API calls are sent and received just fine, the current issue is links to other pages remove the
/prefect/
part and assume top-level, the API calls are made to the right URL however and you still see results (after an initial 404 UI page). I can share a screen video if curious to see it in action, and we can open an issue to track better support for non-base-url hosting like this.
So as a workaround, best to expose it as a subdomain if possible since the above doesn't work so well.
My set-up:
h
Ok, thank you for taking the time to look into this! Yeah, we would love to see support added as this is currently the only thing we can't cleanly tuck into same base URL as our other services. But also understand it's not an easy fix.
πŸ‘ 1
i
h
That looks pretty usable. I will try again as I wasn't getting anything that functional.
πŸ‘ 1
Well, I'm going to give up and stick with the port redirect. I believe I've copied these settings as exactly as possible in my env and I still just get a blank page (and see requests going to /).
Copy code
location /prefect/ {
    include proxy_params;

    if ($ssl_client_verify != "SUCCESS") {
        return 401;
    }

    proxy_pass <http://prefect-server:4200/>;
}
With config:
Copy code
prefect-server:
    entrypoint: [ "prefect", "server", "start" ]
    environment:
      # Instruct the JS UI how to connect to the UI server
      - PREFECT_API_URL=<https://localhost/prefect/api>
      - PREFECT_UI_API_URL=<https://localhost/prefect/api>
      #- PREFECT_UI_API_URL=<http://127.0.0.1:14201/api>
      - PREFECT_SERVER_API_HOST=0.0.0.0
i
Sorry to hear about the troubles. Sounds good, best to hold off till it’s better supported officially.
h
@Islam Otmani, wondering if there is an existing ticket tracking this work (there are a few that appear adjacent) or whether I should just start a new one?
i
Hey! I'm not personally aware of any, feel free to open a new one if you don't think they're exactly this
h
Yeah, I think I've found all the related issues, so I'll link those in. Thank you for quick response!
πŸ‘ 1
i
Perfect! That'll make for a more complelling case if there's demand around the same area πŸ™‚
h
Yes, 100% -- I've opened it here: https://github.com/PrefectHQ/prefect/issues/11472
Thanks again