|
| 1 | +# Load Balancing and Routing |
| 2 | + |
| 3 | +Langflow (at least at version 1.0.15) expects all URLs to be rooted from `/`: there is not a straightforward way to configure a `base_url` or similar. |
| 4 | +This is a challenge for load balancers and other application routers. This goal of this page is to inform you about some tricks you can use |
| 5 | +to configure your own system; it is based on the popular Nginx framework but should be easily translatable to whatever framework you use. |
| 6 | + |
| 7 | +## Server Proxy |
| 8 | + |
| 9 | +Consider this Nginx `server` configuration, which allows Langflow developers to access the UI at `langflow.dev.internal` on port `80`, |
| 10 | +whilst routing requests to `langflow.dev.service` on port `7860`: |
| 11 | + |
| 12 | +``` |
| 13 | + server { |
| 14 | + listen 80; |
| 15 | +
|
| 16 | + server_name langflow.dev.internal; |
| 17 | +
|
| 18 | + location / { |
| 19 | + proxy_pass http://langflow.dev.service:7860; |
| 20 | + proxy_set_header Host $host; |
| 21 | + proxy_set_header X-Real-IP $remote_addr; |
| 22 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 23 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 24 | + } |
| 25 | + } |
| 26 | +``` |
| 27 | + |
| 28 | +## Server Proxy with Routing |
| 29 | + |
| 30 | +To add an application routing based on URL (in this case `/chat`), use the route to identify the destination location, but |
| 31 | +remove the route from the URL before passing to Langflow: |
| 32 | + |
| 33 | +``` |
| 34 | + server { |
| 35 | + listen 80; |
| 36 | +
|
| 37 | + server_name langflow.test.internal; |
| 38 | +
|
| 39 | + location /chat { |
| 40 | + rewrite ^/chat/(.*)$ /$1 break; |
| 41 | + proxy_pass http://langflow.test.service:7860; |
| 42 | + proxy_set_header Host $host; |
| 43 | + proxy_set_header X-Real-IP $remote_addr; |
| 44 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 45 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 46 | + } |
| 47 | + } |
| 48 | +``` |
| 49 | + |
| 50 | +Two important things to note about this routing approach: |
| 51 | + |
| 52 | +1. The Langflow frontend will not work without a '/' location, but backend API calls should. You can combine both locations within the `server` configuration. |
| 53 | +2. Some returned content (such as when an API is called with `stream=true`) includes URLs that will not be prefixed (i.e. `stream_url` will begin `/api/v1/...`); you will need to add the prefix within your application logic. |
| 54 | + |
0 commit comments