Incubator-superset: Configurable basepath/url for nginx reverse proxing on diff location other than /?

Created on 19 Aug 2016  ·  29Comments  ·  Source: apache/incubator-superset

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.

inactive validation

Most helpful comment

so what is the purpose for WEBDRIVER_BASEURL in config?

All 29 comments

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

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 does url_for work correctly? If so it is just matter or using it thoroughly.

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 yes, please!

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.

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"

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.

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?

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 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.

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.

so what is the purpose for WEBDRIVER_BASEURL in config?

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 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?

@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 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?

@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.

@christophlingg problem solved already. thanks

@christophlingg Not all links will be added the prefix right?

我发现为超集设置基本URL非常令人沮丧。如果您想节省时间,请在此处将几个评论压缩成一个有效的示例:https : //github.com/komoot/superset-reverse-nginx-example

I have run according to your configuration, but I am still reporting errors

The mistakes are as follows:

image
image

Looking forward to your help.

@axuew you are right, we need more rewrites, I updated the repository: https://github.com/komoot/superset-reverse-nginx-example/commit/718bb2e8550547a60674a721e12f7da881d481b6

I went down all this path and came to a situation where it worked. Nevertheless it is a dirty and I am now going for solution without base path.

@christophlingg Why need to add (|static|api|...) compared to (static|api|...) ?

@axuew you are right, we need more rewrites, I updated the repository: komoot/superset-reverse-nginx-example@718bb2e

I went down all this path and came to a situation where it worked. Nevertheless it is a dirty and I am now going for solution without base path.

The configuration works according to your method, but there is one fatal error

image
image

@christophlingg Error 503

Screenshot from 2019-11-13 15-07-39

Landed here while trying to configure k8s ingress path based routing to superset.

The nginx solution did no work for me, superset does not consider X-Script-Name when doing redirects and probably has other hardcoded paths, this can be seen also from this nginx location config:

    location ~ ^/(static|superset|sqllab|savedqueryview|druid|tablemodelview|databaseasync|dashboardmodelview|slicemodelview|dashboardasync|druiddatasourcemodelview|api|csstemplateasyncmodelview|chart|savedqueryviewapi|r|datasource|sliceaddview) {
      try_files $uri /analytics/$uri /analytics/$uri?$query_string @rules;
    }

So any of these paths will not hit the correct ingress.

According to this PR comment https://github.com/apache/incubator-superset/pull/1866#issuecomment-659400989, the only solution for now is to use subdomain based routing.

The very fact that htmls are templated by Python is a bad architecture, and needs to be changed. Which is likely to not happen any time soon. Right now there are like 5 different approaches to forming urls, and most of them I consider as a classic hardcode, and hard to fix even if you didn't want to be able to upgrade anymore.

Was this page helpful?
0 / 5 - 0 ratings