2017-12-22 31 views
0

apache2에 배치 된 Flask 앱으로 게시물 요청을 처리하고 싶지만 의도하지 않은 리다이렉션이 있습니다. 또한 요청 본문을 잃어 버립니다. 웹 응용 프로그램을 사용하여 게시물 요청을 실행하고 액세스 로그에 57.39.118.158 - [22/Dec/2017 : 11 : 44 : 32 +0300] "POST/bridge HTTP/1.1"301 3830 "-" " - 57.39.118.158 - - [22/Dec/2017 : 11 : 44 : 32 +0300] "GET/bridge/HTTP/1.1"500 860 "-" "-"오류 로그 : "[Fri Dec 22 11 : 44 : 51.864122 2017] [wsgi : 오류] [pid 28906 : tid 139849921148672] (70008) 부분 결과가 유효하지만 처리가 완료되지 않았습니다. [client 57.39.118.158:35172] mod_wsgi (pid = 28906) : 버킷을 가져올 수 없습니다. 요청한 여단 " 전에 "URL을 찾을 수 없음"이라는 문제가 404 url not found error for flask app on apache2에서 해결되었습니다. 내가 파이썬 3.5.2를 사용하고 있습니다wsgi 오류 : bucket 여단을 요청에 사용할 수 없습니다. & apache2는 게시를 리디렉션합니까?

, 아파치 2.4, OpenSSL을/1.0.2g, 우분투는 16.04, mod_wsgi4.3.0 내가 고유의 conf 파일을 사용하고이처럼이

파이썬 3.5.1+ 컴파일 : /var/www/bridge/bridge.wsgi에서

<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 

파일 /var/www/bridge/bridge.py에서

#!/usr/bin/python3 
import sys 


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

from bridge import app as application 

파일

입니다 0
#!/usr/bin/python3 

from flask import Flask 


app = Flask(__name__) 

@app.route('/', methods =['POST']) 
def deliver(): 
    from flask import request 
    raw=request.get_json(force=True) 
    import mysql.connector 
    dbconn= mysql.connector.connect(host='xx.20.xxx.245',port='3306',database='xxa',user='root',password='Jxxxo') 
    cursor=dbconn.cursor() 
    query1="""insert into bridge_test2 (email) values ('blah')""" 
    query2="""insert into bridge_test2 (email) values ('{}')""".format(raw) 
    cursor.execute(query1) 
    dbconn.commit() 
    cursor.execute(query2) 
    dbconn.commit() 
    dbconn.close() 
    return 'ok' 

if __name__ == '__main__': 
    app.run() 

파일 권한 :

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은 sudo는 privilage와 사용자입니다. 활성화 개조는 다음과 같습니다

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. load 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

재로드 문제가 발생할 수 있습니다? 어떤 제안?

답변

0

나는 아마 행동이 예상된다고 말할 것이다.

URL의 마운트 지점은 /bridge이며 이는 URL의 경로에서 사용하고 있습니다. 이것은 다음으로 번역됩니다 :

SCRIPT_NAME=/bridge 
PATH_INFO= 

플라스크로 전달 된 경우. 경로가 설정되는 방식으로, 플라스크를 볼 것으로 예상된다

결과
SCRIPT_NAME=/bridge 
PATH_INFO=/ 

는, 플라스크는 후행 슬래시를 추가 할 브라우저를 강제로 리디렉션을 강제.

문제는 핸들러 만 POST을 기대하고 일반적으로 재 항상 핸들러는 POST을 허용하기 때문에 발견되는 다음 핸들러가 결과 GET되는 후속 요청을 초래할 것입니다.

즉, 자동 후행 슬래시 리디렉션의 대상이 될 수있는 경로에 POST 처리기가있는 것이 바람직하지 않습니다. 이 경우 마운트 지점이 하위 URL 일 때 WSGI 응용 프로그램의 탑재 지점에서 처리기를 사용할 때 이런 현상이 발생합니다.

처리기가 작동했음을 테스트하려면 브라우저에서 /bridge 대신 URL에 /bridge/을 사용하십시오. 더 나은 여전히 ​​POST 처리기를 WSGI 응용 프로그램에 대한 탑재 지점 이외의 다른 경로로 이동하십시오.

다른 이상한 아파치 오류에 대해서는 보안 연결을 사용할 때 오류로 인해 연결이 끊어 질 때가 있습니다.

+0

내 처리기를 마운트 지점에서 옮기면 작동합니다. :) 고마워! – dogacan