Setting up Apache Superset with Nginx as Reverse Proxy
Asked Answered
U

1

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.

Uranography answered 24/8, 2017 at 14:58 Comment(1)
Instead of using 0.0.0.0 try using 127.0.0.1 in both nginx proxy_pass and browserFrias
T
6

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, ]
Tivoli answered 15/1, 2018 at 10:51 Comment(3)
Thank you for this, I'm trying your solution but am stuck on where to put superset-config.py. Any pointers gratefully appreciated.Southwestward
@mappingdom I have it in the same directory where you run the superset runserver command, should be picked upTivoli
This is a great solution, but breaks most of the static content as the browser requests them with the /static prefix and not /superset/staticDetinue

© 2022 - 2024 — McMap. All rights reserved.