When reverse proxying datasette with nginx an URL element gets erronously added
I use this nginx config:
location /datasette-llm {
return 302 /datasette-llm/;
}
location /datasette-llm/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_http_version 1.1;
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 https;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header Host $host;
proxy_max_temp_file_size 0;
proxy_pass http://127.0.0.1:8001/datasette-llm/;
proxy_redirect http:// https://;
proxy_buffering off;
proxy_request_buffering off;
proxy_set_header Origin '';
client_max_body_size 0;
auth_basic "datasette-llm";
auth_basic_user_file /etc/nginx/custom-userdb;
}
Then I start datasette with this command:
datasette serve --setting base_url /datasette-llm/ $(llm logs path)
Everything else works right, except the links in "This data as json, CSV". They get an extra URL element "datasette-llm" like this:
https://192.168.1.3:5432/datasette-llm/datasette-llm/logs.json?sql=select+*+from+_llm_migrations
https://192.168.1.3:5432/datasette-llm/datasette-llm/logs.csv?sql=select+*+from+_llm_migrations&_size=max
When I remove that extra "datasette-llm" from the URL, those links work too.
The same problem can be seen in the links:
Advanced export
JSON shape: default, array, newline-delimited, object
I forgot to add that I followed these instructions to set up the python llm:
https://simonwillison.net/2023/Jul/18/accessing-llama-2/
I must be doing something wrong. On page https://192.168.1.3:5432/datasette-llm/logs/_llm_migrations there's the option to filter the results, there's an Apply button. It also tries to load an URL with an extra URL element in it:
https://192.168.1.3:5432/datasette-llm/datasette-llm/logs/_llm_migrations?_sort=name&name__contains=initial
datasette does not seem to handle X-Forwarded-Proto. It should be patched to be aware of it.
https://github.com/simonw/datasette/blob/452a587e236ef642cbc6ae345b58767ea8420cb5/datasette/app.py#L1032-L1036