support for setting baseurl to "/plexivity" to allow reverse proxing

Issue #37 resolved
Former user created an issue

No description provided.

Comments (9)

  1. Devin Buhl

    After some diggin around I found a way which gives you partial support for having a reverse proxy, but @Raphael needs to update a few links to make it work 100%. A few things I noticed was The setup submit button needs to be changed and the history page doesn't load (there are some ajax errors)..

    In app/__init__.py under the line:

    from flask.ext.restless import APIManager, ProcessingException
    

    add

    class ReverseProxied(object):
        '''Wrap the application in this middleware and configure the 
        front-end server to add these headers, to let you quietly bind 
        this to a URL other than / and to an HTTP scheme that is 
        different than what is used locally.
    
        In nginx:
        location /myprefix {
            proxy_pass http://192.168.0.1:5001;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header X-Script-Name /myprefix;
            }
    
        :param app: the WSGI application
        '''
        def __init__(self, app):
            self.app = app
    
        def __call__(self, environ, start_response):
            script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
            if script_name:
                environ['SCRIPT_NAME'] = script_name
                path_info = environ['PATH_INFO']
                if path_info.startswith(script_name):
                    environ['PATH_INFO'] = path_info[len(script_name):]
    
            scheme = environ.get('HTTP_X_SCHEME', '')
            if scheme:
                environ['wsgi.url_scheme'] = scheme
            return self.app(environ, start_response)
    

    then under

    app = Flask(__name__)
    

    add

    app.wsgi_app = ReverseProxied(app.wsgi_app)
    

    Now in nginx make a location something like..

    location /plexivity {
            proxy_set_header X-Script-Name /plexivity;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Host $proxy_add_x_forwarded_for;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_connect_timeout 60;
            proxy_read_timeout 60;
            proxy_pass        http://localhost:8000;
    }
    
  2. Raphael Mutschler repo owner

    Thanks, i have currently a lot of stuff todo but i'll definitively check this out!

    The History page most likely doesn't load because it requests /load/histroy which would become plexivity/load/histroy when you'll use a proxy... i think that could be fixed easily by passing the script name variable to the template engine as well :)

  3. Raphael Mutschler repo owner

    @wingmannz @onedr0p i've implemented this in the latest development branch, can you test and verify?

  4. Devin Buhl

    Thanks!! I'll give it a shot tomorrow, after a brief overview of the commits I believe there shouldn't be any issues unless you missed any other urls ;)

  5. Devin Buhl

    A few issues issues I've noticed from a fresh install:

    in app/templates/setup.html the form url should be this:

            {{ render_form(form, action_url=url_for('setup'), action_text=_('Create Account'), btn_class='btn btn-plex') }}
    

    and in app/templates/settings.html the form url should be this:

                {{ render_form(form, action_url='settings', action_text=_('Save settings'), btn_class='btn btn-plex') }}
    

    Note: they are missing the preceding slash.

    Other that those 2 issues I've only had a few redirect issues when trying to do a fresh install thru the proxy, which you can remedy by actually going to the URL if the page 404s or redirects to a non existent page.

    I'm going to let the app run for awhile and see if I notice anything else that might be an issue. Sadly I don't have any data to work with yet. :/

  6. sea3pea0

    So I got this mostly working on apache:

    <Location /plexivity>
    RequestHeader set X-Script-Name /plexivity
    RequestHeader set X-Scheme https
    ProxyPass http://localhost:[port]
    ProxyPassReverse http://localhost:[port]
    </Location>
    

    It works pretty flawlessly except for the logout button. If I click logout from the main page I am redirected to the root of my webserver, for example "http://mysite.com". If I am on any of the other pages such as history or charts when I click logout, I am redirected to "http://mysite.com/history" and of course in this situation I get a 404 page not found. Anybody have any tips on a better way to set up this reverse proxy on apache?

  7. Log in to comment