On Jul 15, 8:22 pm, Armin Ronacher <[email protected]>
wrote:
> Hi.
>
> There is a documentation for HTTP proxying with nginx in the docs:
>
> http://werkzeug.pocoo.org/documentation/0.5.1/deployment/proxying.html
>
> Unfortunately I'm not using nginx myself with proxying so I can't help
> you there.  If that does not help you might want to ask the guys on
> the nginx mailinglist.  Also, if there is anything missing in the
> documentation, I'm glad to accept documentation patches so that the
> docs help other users as well.

the problem is, that only works when proxying under is done for the
root of the nginx server i.e. "location /" .. it breaks when you want
to proxy under let's say /app1

I've ended up making a simplest WSGI middleware
def proxy_fix(app, prefix=''):
    def wsgi_app(env, start_response):
        if 'HTTP_X_FORWARDED_FOR' in env:
            env['SCRIPT_NAME'] = prefix + env['SCRIPT_NAME']
        return app(env, start_response)
    return wsgi_app
...
app = proxy_fix(app, '/app1')

with headers added in nginx, I could also go away with the explicit
prefix in the middleware... maybe something like:

def proxy_fix(app):
    def wsgi_app(env, start_response):
        if 'HTTP_NGINX_PREFIX' in env:
            env['SCRIPT_NAME'] = env['HTTP_NGINX_PREFIX'] + env
['SCRIPT_NAME']
        return app(env, start_response)
    return wsgi_app

nginx would then need to be configured like:

        location /app1/ {
            rewrite /app1/(.*) /$1 break;
            proxy_pass http://127.0.0.1:5000;
            proxy_set_header   Nginx-Prefix     "/app1";
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For
$proxy_add_x_forwarded_for;
        }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to