404在apache2上找不到flask应用程序的url错误

2024-09-29 23:19:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Flask编写了一个端点来处理json格式的httppost请求数据。当尝试在apache2上部署它时,post请求得到404错误:“请求的URL/bridge在此服务器上找不到”。我使用的是python3.5.2、apache2.4、OpenSSL/1.0.2g、ubuntu 16.04、mod帴wsgi4.3.0为python3.5.1+编译的

有人知道吗?Apache看不到/var/www,但为什么呢?或者SSL配置有问题?(https适用于webiste)

我有

网址/var/www/bridge/桥.wsgi在

#!/usr/bin/python3
import sys

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

from bridge import app as application

已启用/etc/apache2/sites上的conf文件/桥.conf在

^{pr2}$

我的000-默认.conf文件如下:

<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 www.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
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

# 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

# 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>

<VirtualHost *:80>
ServerName  newocto.org/
Redirect / https://newocto.org/
</VirtualHost>

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

我的烧瓶代码在/var/www/bridge/桥.py是

#!/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)
    return raw

import mysql.connector
dbconn=  mysql.connector.connect(host='xxxx',port='3306',database='xx',user='root',password='xxx')
cursor=dbconn.cursor()
query="""insert into bridge_test2 (email) values ('{}')""".format(raw)
cursor.execute(query)
dbconn.commit()
dbconn.close()


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



#file permissions are like this:   
#4 -rwxr-xr-x 1 root www-data 537 Dec 20 13:46 bridge.py
#4 -rwxr-xr-x 1 root www-data 117 Dec 20 14:10 bridge.wsgi

Tags: thefromimportapphostisvarconf

热门问题