2016-03-28 6 views
0

Ich bin eine Flasche App mit Gunicorn hinter Nginx Proxy laufen und versuche, den Gaiohttp Arbeiter zur Arbeit zu bekommen. Die App gibt 404 nur für alle URLs zurück, wenn der gaiohttp-Worker ausgewählt istGunicorn mit gaiohttp Arbeiter immer 404 mit Kolben App

Wenn die Synchronisierung oder Gevent-Worker funktioniert alles einwandfrei. Auch läuft nicht direkt zu Gunicorn und Gaiohttp, d. H. Nicht mit Nginx funktioniert es gut.

Ich habe alles gelesen, was ich finden kann.

Fehle ich etwas? Ist gaiohttp worker gültig, wenn er hinter einem nginx-Proxy ausgeführt wird?

Meine nginx config:

location /app { 
    proxy_pass http://127.0.0.1:9002; 
    rewrite /app(.*) /$1 break; 
    proxy_redirect  off; 
    proxy_buffering on; 
    proxy_pass_header Server; 
    proxy_set_header X-Scheme $scheme; 
    proxy_set_header Host    $host; 
    proxy_set_header X-Real-IP  $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Host $server_name; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_set_header X-Script-Name /app; 
    } 

gunicorn:

/usr/bin/gunicorn --workers 2 -k gaiohttp -b 127.0.0.1:9002 app:app 

Mit den neuesten Versionen von gunicorn etc etc.

Antwort

0

ich es geschafft, dies zu erarbeiten.

Die Linie wurde hier das Problem in der nginx Konfiguration verursacht:

rewrite /app(.*) /$1 break;

Und ich brauchte eine Proxy-Middleware in meinem Flask App, den Reverse-Proxy richtig zu handhaben.

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: 
     server = environ.get('HTTP_X_FORWARDED_SERVER', '') 
     if server: 
      environ['HTTP_HOST'] = server 
     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) 

Im __init__.py der App: app.wsgi_app = ReverseProxied(app.wsgi_app)