2017-12-22 11 views
0

Ich möchte eine Post-Anfrage mit einer Flask-App behandeln, die auf Apache2 implementiert ist, aber ich habe eine unbeabsichtigte Umleitung bekommen. es verliert auch Anfrage Körper. Ich trigger eine Post-Anfrage mit einer Web-App und Zugriffsprotokoll sagt: 57.39.118.158 - - [22/Dez/2017: 11: 44: 32 +0300] "POST/Brücke HTTP/1.1" 301 3830 "-" " - " 57.39.118.158 - - [22/Dez/2017: 11: 44: 32 +0300]" GET/bridge/HTTP/1.1 "500 860" - "" - "und Fehlerprotokoll: " [Fr Dec 22 11: 44: 51.864122 2017] [wsgi: error] [pid 28906: tid 139849921148672] (70008) Teilergebnisse sind gültig, aber die Verarbeitung ist unvollständig: [client 57.39.118.158:35172] mod_wsgi (pid = 28906): Kann Eimer nicht bekommen Brigade für Anfrage. " Vorher ist das Problem "URL nicht gefunden" bei 404 url not found error for flask app on apache2 gelöst.wsgi error: Kann Eimerbrigade für Anfrage nicht erhalten & apache2 leitet Pfosten weiter, um zu erhalten?

Ich verwende Python 3.5.2, Apache 2.4, OpenSSL/1.0.2g, ubuntu 16.04, mod_wsgi4.3.0 für Python kompiliert 3.5.1+

Ich habe eine einzigartige conf Datei aktiviert und ist wie folgt :

<VirtualHost *:443> 
# The ServerName directive sets the request scheme, hostname and port that 
# the server uses to identify itself. This is used when creating 
# redirection URLs. In the context of virtual hosts, the ServerName 
# specifies what hostname must appear in the request's Host: header to 
# match this virtual host. For the default virtual host (this file) this 
# value is not decisive as it is used as a last resort host regardless. 
# However, you must set it for any further virtual host explicitly. 
ServerName newocto.org 
DocumentRoot /var/www/html 

SSLEngine on 
SSLCertificateFile /etc/ssl/certs/newocto_org.crt 
SSLCertificateKeyFile /etc/ssl/private/newocto.key 
SSLCertificateChainFile /etc/ssl/certs/COMODORSAAddTrustCA.crt 


# Available loglevels: trace8, ..., trace1, debug, info, notice, warn, 
# error, crit, alert, emerg. 
# It is also possible to configure the loglevel for particular 
# modules, e.g. 
#LogLevel info ssl:warn 

ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined 

WSGIDaemonProcess bridge user=dogacandu group=dogacandu threads=5 home=/var/www/bridge/ 
WSGIScriptAlias /bridge /var/www/bridge/bridge.wsgi 


<Directory /var/www/bridge> 
WSGIProcessGroup bridge 
WSGIApplicationGroup %{GLOBAL} 
Require all granted 

</Directory> 

# For most configuration files from conf-available/, which are 
# enabled or disabled at a global level, it is possible to 
# include a line for only one particular virtual host. For example the 
# following line enables the CGI configuration for this host only 
# after it has been globally disabled with "a2disconf". 
#Include conf-available/serve-cgi-bin.conf 
</VirtualHost> 

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

Datei auf /var/www/bridge/bridge.wsgi ist

#!/usr/bin/python3 
import sys 


sys.path.insert(0,'/var/www/bridge') 

from bridge import app as application 

Datei auf /var/www/bridge/bridge.py ist

Dateiberechtigungen:

4 -rwxr-xr-x 1 root dogacandu 654 Dec 21 17:31 bridge.py 
4 -rwxr-xr-x 1 root dogacandu 117 Dec 20 18:26 bridge.wsgi 

dogacandu ist Benutzer mit sudo privilage. aktiviert Mods sind:

access_compat.load authn_core.load authz_user.load cgid.load dir.load mime.load negotiation.load socache_shmcb.load status.load alias.conf authn_file.load autoindex.conf deflate.conf env. laden mpm_event.conf rewrite.load ssl.conf wsgi.conf alias.load authz_core.load autoindex.load deflate.load filter.load mpm_event.load setenvif.conf ssl.load wsgi.load auth_basic.load authz_host.load cgid. conf dir.conf mime.conf negotiation.conf setenvif.load status.conf

kann rewrite.load Ursache Umleitung Problem? Irgendwelche Vorschläge?

Antwort

0

Ich würde sagen, dass das Verhalten wahrscheinlich erwartet wird.

Der Mount-Punkt für die URL ist /bridge und das ist, was Sie im Pfad für die URL verwenden. Dies wird übersetzt in:

SCRIPT_NAME=/bridge 
PATH_INFO= 

wenn an Flask übergeben. Mit der Art und Weise wird die Route eingerichtet, erwartet Flask zu sehen:

SCRIPT_NAME=/bridge 
PATH_INFO=/ 

als Ergebnis zwingt Flask eine Umleitung um den Browser zu zwingen, einen Schrägstrich hinzuzufügen.

Das Problem ist, dass Ihr Handler erwartet nur POST und in der Regel eine Umleitung wird immer in der nachfolgenden Anforderung führt ein GET sein, die dann in keine Handler Ergebnisse gefunden werden, da der Handler nur POST akzeptiert.

Kurz gesagt, es ist eine schlechte Idee, einen POST Handler auf einer Route zu haben, die Gegenstand einer automatischen Schrägstrichumleitung sein kann. In diesem Fall geschieht dies, da Sie den Handler am Mount der WSGI-Anwendung haben, wenn der Mount-Punkt eine Sub-URL ist.

Um zu testen, ob der Handler funktioniert hat, verwenden Sie in Ihrem Browser /bridge/ in Ihrer URL anstelle von /bridge. Besser noch bewegen Sie Ihre POST Handler auf eine andere Route als der Mount-Punkt für die WSGI-Anwendung.

Was die anderen seltsamen Apache-Fehler angeht, können Sie das manchmal bekommen, wenn Verbindungen aufgrund von Fehlern abgebaut werden, wenn sichere Verbindungen verwendet werden.

+0

Ich habe meinen Handler vom Mount-Punkt entfernt und es funktioniert :) Danke, Alter! – dogacan

Verwandte Themen