Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michailsal opened this issue Aug 19, 2016 · 36 comments
Labels
inactive Inactive for >= 30 days validation:required A committer should validate the issue

Comments

@michailsal
Copy link

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.

@xrmx
Copy link
Contributor

xrmx commented Aug 19, 2016

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

@xrmx xrmx added the validation:required A committer should validate the issue label Aug 20, 2016
@michailsal
Copy link
Author

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?

@xrmx
Copy link
Contributor

xrmx commented Aug 22, 2016

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

@michailsal
Copy link
Author

michailsal commented Aug 23, 2016

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?

@xrmx
Copy link
Contributor

xrmx commented Aug 23, 2016

@michailsal yes, please!

@cuph62
Copy link

cuph62 commented Oct 11, 2016

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.

@michailsal
Copy link
Author

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"

@andreaslang
Copy link

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.

@rsxm
Copy link
Contributor

rsxm commented Dec 8, 2016

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?

@joharohl
Copy link

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.

@xrmx
Copy link
Contributor

xrmx commented Dec 14, 2016

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

@mistercrunch
Copy link
Member

related #3690

@stale
Copy link

stale bot commented Apr 11, 2019

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 stale bot added the inactive Inactive for >= 30 days label Apr 11, 2019
@stale stale bot closed this as completed Apr 18, 2019
@dpgaspar dpgaspar mentioned this issue May 9, 2019
3 tasks
@Congee
Copy link

Congee commented Jul 17, 2019

so what is the purpose for WEBDRIVER_BASEURL in config?

@christophlingg
Copy link
Contributor

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

@syazshafei
Copy link

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

@christophlingg
Copy link
Contributor

@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

@syazshafei
Copy link

@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
Copy link

@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
Copy link

@christophlingg problem solved already. thanks

@syazshafei
Copy link

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

@axuew
Copy link
Contributor

axuew commented Nov 12, 2019

我发现为超集设置基本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.

@christophlingg
Copy link
Contributor

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

@syazshafei
Copy link

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

@axuew
Copy link
Contributor

axuew commented Nov 13, 2019

@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
Copy link
Contributor

With a this new commit it should work as expected: komoot/superset-reverse-nginx-example@e18421e

@syazshafei
Copy link

@christophlingg Error 503

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

@acristu
Copy link

acristu commented Oct 20, 2020

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 #1866 (comment), the only solution for now is to use subdomain based routing.

@yhaiovyi
Copy link

yhaiovyi commented Dec 8, 2020

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.

@syazshafei
Copy link

Anyone able to configure the url using latest Superset?

@andrey-mikhailov
Copy link

andrey-mikhailov commented Jul 23, 2021

I created a script that adds prefix to hardcoded URLs in python and js code in Superset image and added middleware and nginx. But it is a very hacky way.

@alexleach
Copy link

Just landed on this having been looking for a way to configure a base url path. Like others, I was hoping to find an easy and supported way of configuring the superset base url. With docker-compose being the first documented way to launch superset, I'd have thought there would be good options!

I tend to proxy my containers through traefik, using a PathPrefix directive, which map to a base url configuration option. By using base urls instead of subdomains allows me to use a single SSL certificate on the traefik proxy to host a number of web apps and services. Requiring separate subdomains means more SSL certificate requests and renewals, which is a bit of a chore, so I'd far prefer to route requests based on base urls than on subdomains.

I checked out the superset-reverse-nginx-example, in traefik that would be a lot of PathPrefix options to configure! It would be possible of course, but really not ideal!

From the above comments, it looks like the js is currently limiting a configurable base url, in that the js hosts most of the hard-coded URLs. Is this still the case? Does anyone know if there is a way to rebuild the repo from typescript with a configurable base url? e.g. PR #15105

@nytai
Copy link
Member

nytai commented Aug 20, 2021

@alexleach There are just too many urls to track down and convert, on both the python and js/ts side. The best option right now would be an nginx rewrite based on a regex, as @acristu mentioned but it is very hacky and likely to break anytime superset adds a new route.

@alexleach
Copy link

@nytai Thanks for the quick reply! Yes the codebase is pretty huge, and tracking it all down looks like it would be a mission. I'd personally not have a clue where to begin, so will have to go the subdomain route and get a dedicated SSL certificate for it, which isn't ideal, but as you say there are too many possible places to track down and convert, and I wouldn't have a clue what to do even if I found one! Thanks

zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 17, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 24, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 25, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 26, 2021
@zhangzhenhu
Copy link

Six years passed, but this issue is still. motherfucker!

@christophlingg
Copy link
Contributor

mind you language @zhangzhenhu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Inactive for >= 30 days validation:required A committer should validate the issue
Projects
None yet
Development

No branches or pull requests