6

I'm having trouble setting up apache superset with Nginx as a reverse proxy (This is probably an nginx misconfig).

Server block of config (if I'm missing something, let me know and I'll add it):

server {
    listen 80 default_server;
    server_name _;
    root /var/www/data;
    error_log   /var/www/bokehapps/log/nginx.error.log info;
    location /static {
        alias /usr/lib/python2.7/site-packages/bokeh/server/static;
    }

 
    location /superset {
        proxy_pass http://0.0.0.0:8088;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_connect_timeout 600;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        send_timeout 600;
    }
}

I'm able to curl into 0.0.0.0:8088 to get a redirect page, and my request are making it to werkzeug. But in my browser, everything is 404.

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

5

Since you are serving on a prefixed location (/superset), and even though you are proxy passing to /, werkzeug is trying to serve /superset route, which does not exist, hence 404.

What you should to is define a prefix middleware, a very nice explanation can be found in this thread: Add a prefix to all Flask routes .

The middleware should than be passed to Superset/FAB as part of the superset-config.py, relevant documentation

Combining the two you'll likely end up with something like this in your superset-config.py:

class PrefixMiddleware(object):

def __init__(self, app, prefix='superset'):
    self.app = app
    self.prefix = prefix

def __call__(self, environ, start_response):

    if environ['PATH_INFO'].startswith(self.prefix):
        environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):]
        environ['SCRIPT_NAME'] = self.prefix
        return self.app(environ, start_response)
    else:
        start_response('404', [('Content-Type', 'text/plain')])
        return ["This url does not belong to the app.".encode()]
    
ADDITIONAL_MIDDLEWARE = [PrefixMiddleware, ]
TylerH
  • 20,799
  • 66
  • 75
  • 101
Drazen Urch
  • 2,781
  • 1
  • 21
  • 23
  • Thank you for this, I'm trying your solution but am stuck on where to put superset-config.py. Any pointers gratefully appreciated. – mapping dom Jan 31 '19 at 10:28
  • @mappingdom I have it in the same directory where you run the `superset runserver` command, should be picked up – Drazen Urch Feb 02 '19 at 22:54
  • 1
    This is a great solution, but breaks most of the static content as the browser requests them with the `/static` prefix and not `/superset/static` – ramdesh Oct 08 '19 at 16:31