Run Libretranslate on a subpath

I would like to run Libretranslate on a given subpath, e.g., https://example.com/translate. I’ve managed to serve some contents of Libretranslate using WSGI and Gunicorn with the following syntax:

SCRIPT_NAME=/translate ./venv/bin/gunicorn --bind 0.0.0.0:5000 --log-level 'DEBUG' 'wsgi:app'

However, the Swagger URL, for example, is not set and the hyperlink shows https://example.com/docs.
What else should I need to add that does not involve manually rewriting routes in code?

1 Like

Try:

SCRIPT_NAME=/translate ./venv/bin/gunicorn --bind 0.0.0.0:5000 --log-level 'DEBUG' 'wsgi:app(url_prefix="translate")'
1 Like

Does not work:

[2023-02-10 23:34:42 +0000] [28] [INFO] Starting gunicorn 20.1.0
[2023-02-10 23:34:42 +0000] [28] [DEBUG] Arbiter booted
[2023-02-10 23:34:42 +0000] [28] [INFO] Listening at: http://0.0.0.0:5000 (28)
[2023-02-10 23:34:42 +0000] [28] [INFO] Using worker: sync
[2023-02-10 23:34:42 +0000] [30] [INFO] Booting worker with pid: 30
[2023-02-10 23:34:42 +0000] [28] [DEBUG] 1 workers
[2023-02-10 23:34:48 +0000] [30] [DEBUG] GET /translate
[2023-02-10 23:34:48 +0000] [30] [DEBUG] GET /favicon.ico
[2023-02-10 23:34:48 +0000] [30] [ERROR] Error handling request /favicon.ico
Traceback (most recent call last):
  File "/app/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 136, in handle
    self.handle_request(listener, req, client, addr)
  File "/app/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 169, in handle_request
    resp, environ = wsgi.create(req, client, addr,
  File "/app/venv/lib/python3.8/site-packages/gunicorn/http/wsgi.py", line 183, in create
    path_info = path_info.split(script_name, 1)[1]
IndexError: list index out of range

I have this same issue, see below for what I am looking at:

ip/subpath/ returns 200
after the initial page loads the following happens:
ip/static/* returns 404 notice that this request does not use the subpath anymore, and even if I try to put a url rewrite in it fails
ip/subpath/js/app.js?v=1.3.9 return 200

this service is running behind a reverse proxy, when connected directly to the service via assigned ip port combo everything loads as it should.

I believe this is an issue with the service not moving everything behind the subpath which leads to a 404 on some items with reverse proxying

so I guess the question is: How do we get the /static/ files to be served from the ip/url_prefix/static/ instead of ip/static/?