我使用虚拟机运行烧瓶应用程序“ sqtf”。她使用127.0.0.1:5000在本地工作,但不适用于我的apache服务器。我使用python3.6,apache2.4和mod_wsgi。
这是我的项目的简化结构:
/var/www/squashPy/src/squash_test_filter/
/sqtf
sqtf.wsgi
__init__.py
/static
/templates
/venv
在apache上配置我的VirtualHost'sqtf.com.conf',然后在我的sqtf.wsgi(还配置我的virtualenv和/ etc / hosts)上配置服务器之后,服务器会在www.sqtf.com上做出响应,但会在我的登录页面或其他任何位置上做出响应, www.sqtf.com/auth/login'504网关超时服务器端口80。
在我的error.log中:
从守护进程'sqtf'读取响应时超时:/var/www/squashPy/src/squash_test_filter/sqtf/sqtf.wsgi
我在DeamonProcess中添加了一个python-home。
增加超时不会更改任何内容。
我的sqtf.com.conf
<VirtualHost *:80>
ServerName www.sqtf.com
ServerAlias sqtf.com
ErrorLog /var/www/squashPy/sqtf.com/logs/error.log
CustomLog /var/www/squashPy/sqtf.com/logs/custom.log combined
WSGIDaemonProcess sqtf python-home='var/www/squashPy/src/squash_test_filter/venv'
WSGIProcessGroup sqtf
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/..../sqtf/sqtf.wsgi
Alias /static/ /var/wwww/..../sqtf/static
<Directory /var/www/..../static>
Require all granted
</Directory>
<VirtualHost>
我的sqtf.wsgi
activate_this='/var/www/..../venv/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
import logging
sys.path.insert(0, "/var/www/squashPy/src/squash_test_filter/")
from sqtf import app as application
我的/ etc / hosts的一部分:
127.0.0.1 localhost
127.0.1.1 ubuntu
127.0.0.1 www.sqtf.com sqtf.com sqtf
# etc ...
我的/sqtf/init.py的一部分
import ...
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
api = Api(app)
app.config.from_mapping(
SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'sqtf.sqlite'),
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
db.init_app(app)
return app
参考方案
我解决了这个问题,例如,如果您使用烧瓶工厂,例如create_app,则需要通过以下方式在.wsgi中更改此行from sqtf import app as application
:
from sqtf import create_app
application=create_app()
Python sqlite3数据库已锁定 - python我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…
Python-Excel导出 - python我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…
Python:传递记录器是个好主意吗? - python我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…
Python pytz时区函数返回的时区为9分钟 - python由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…
用大写字母拆分字符串,但忽略AAA Python Regex - python我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…