superset icon indicating copy to clipboard operation
superset copied to clipboard

Configurable basepath/url for nginx reverse proxing on diff location other than /?

Open michailsal opened this issue 10 years ago • 36 comments

Is there any way to configure caravel to accept requests under /my-whatever-path/.....? I would like to reverse proxy caravel using nginx but not on / location block.

michailsal avatar Aug 19 '16 11:08 michailsal

Google suggests this http://flask.pocoo.org/snippets/35/ . Feel free to open a pull request if it works for you.

xrmx avatar Aug 19 '16 13:08 xrmx

It did work, but then I ran into countless absolute links that I haven't found a way to put them behind a prefix. Any ideas?

michailsal avatar Aug 22 '16 18:08 michailsal

@michailsal does url_for work correctly? If so it is just matter or using it thoroughly.

xrmx avatar Aug 22 '16 19:08 xrmx

url_for does work for the most part, but still there are many hardcoded absolute links e.g.

./templates/caravel/sql.html:      <img id="loading" width="25" style="display: none;" src="/static/assets/images/loading.gif">
./templates/caravel/welcome.html:          <img class="loading" src="/static/assets/images/loading.gif"/>
./templates/caravel/explore.html:            <img src="{{ url_for("static", filename="assets/images/loading.gif") }}" class="loading" alt="loading">
./templates/caravel/standalone.html:      <img src="{{ url_for("static", filename="img/loading.gif") }}" class="loading" alt="loading">

Shall I just fix them by adding url_for (which I have already done locally) and open a pull request?

michailsal avatar Aug 23 '16 11:08 michailsal

@michailsal yes, please!

xrmx avatar Aug 23 '16 11:08 xrmx

Is there any news regarding these changes / pull request ?

The same issue applies on wsgi serving with Apache for example: in apache config: WSGIScriptAlias /myapp /var/www/dashboard/flaskacct.wsgi

but immediately I get a 404 with http://myhost/caravel/welcome without preserving the baseurl like http://myhost/myapp/caravel/welcome.

cuph62 avatar Oct 11 '16 08:10 cuph62

I haven't had time to work on this, I do know though that even if somehow you manage to preserve the baseurl and not being redirected, there are still many absolute links pointing to "/" instead of using "url_for"

michailsal avatar Oct 11 '16 10:10 michailsal

Somewhat related to this, I did a brute force thing with apache to get it (almost) working:

ProxyPass /caraveldata/ http://caravel:8088/
ProxyPassReverse /caraveldata/ http://caravel:8088/

<Location /caraveldata/>
    Header edit Location ^https?://([^/]+)/(.*)$ https://$1/caraveldata/$2

    RequestHeader unset Accept-Encoding
    ProxyHTMLEnable On
    ProxyHTMLExtended On
    ProxyHTMLURLMap / /caraveldata/
    ProxyHTMLURLMap /caraveldata/ /caraveldata/
</Location>

This almost works, but then I run into issues with JavaScript, because it does things like for example in welcome.js:

// Builds a dataTable from a flask appbuilder api endpoint
let url = '/' + modelView.toLowerCase() + '/api/read';

I don't see a good way of fixing that, without touching caravel source code in quite a few places. I am considering to introduce another sub-domain to be able to proxy my backend caravel app without the need to use paths. I was just trying to avoid it because another sub-domain means I need to separately configure it with our single-sing-on.

andreaslang avatar Oct 31 '16 15:10 andreaslang

Is anyone working this? I just tried to put Gunicorn (serving Superset) behind an nginx proxy. Some links work, but others didn't.

This is relevant part from my nginx config file:

location /prefix/ { proxy_pass http://172.26.0.4:8088/prefix/; # <- gunicorn server proxy_set_header SCRIPT_NAME /prefix; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

In Superset, I tried with and without ENABLE_PROXY_FIX (not sure what this setting does?). So without digging deeper, it looks like the issue is still hardcoded urls?

rsxm avatar Dec 08 '16 14:12 rsxm

I have made a proof of concept that works behind a proxy.

The python code changes were fairly straightforward by switching hard coded urls for Flasks' url_for.

The JS though... I just did the hacky thing by templating serverRoot and staticRoot global js variables that are then used to build the urls. It works fine, but is probably not the best.

I would love to contribute this back, but need some guidance on how to approach the JS side of things.

joharohl avatar Dec 14 '16 12:12 joharohl

@joharohl if we have the code i'd say to just open a PR for the python code and we can discuss about the js. We can update the PR later or just open a new one.

xrmx avatar Dec 14 '16 13:12 xrmx

related https://github.com/apache/incubator-superset/issues/3690

mistercrunch avatar Nov 28 '17 05:11 mistercrunch

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Apr 11 '19 06:04 stale[bot]

so what is the purpose for WEBDRIVER_BASEURL in config?

Congee avatar Jul 17 '19 22:07 Congee

I found it very frustrating to setup a base url for superset. If you want to save some time, I condensed a couple of comments into a working example here: https://github.com/komoot/superset-reverse-nginx-example

christophlingg avatar Sep 24 '19 12:09 christophlingg

@christophlingg So how to implement your working example in latest apache superset on master by running it under gunicorn? Just need to have the nginx in docker-compose.yml and nginx.conf right?

syazshafei avatar Oct 02 '19 05:10 syazshafei

@syazwan0913 I dont know if there are already docker images for the current master. you can try put latest in the docker version here https://github.com/komoot/superset-reverse-nginx-example/blob/master/docker-compose.yml#L13

see also https://github.com/amancevice/docker-superset#versions

christophlingg avatar Oct 02 '19 05:10 christophlingg

@christophlingg Right now I am using the code from here https://github.com/apache/incubator-superset

When I used your nginx.conf, the site can be load and the URL prefix is based on my configuration. But the problem is static files like html, js, images is not showing. Is it I missing something?

syazshafei avatar Oct 02 '19 05:10 syazshafei

@christophlingg the static files showed already but another problem came up. When I run docker-compose up --build -d, there is problem with it run RUN rm /etc/nginx/conf.d/default.conf.

syazshafei avatar Oct 04 '19 00:10 syazshafei

@christophlingg problem solved already. thanks

syazshafei avatar Oct 27 '19 10:10 syazshafei