I use a virtual machine to run my flask app 'sqtf'. She works on local using 127.0.0.1:5000, but not with my apache server. I use python3.6, apache2.4 and mod_wsgi. this is a simplified structure of my project:
/var/www/squashPy/src/squash_test_filter/
/sqtf
sqtf.wsgi
__init__.py
/static
/templates
/venv
After configuring my VirtualHost 'sqtf.com.conf' on apache and then my sqtf.wsgi (configuring also my virtualenv and /etc/hosts), the server respond at www.sqtf.com but in my login page or any other, 'www.sqtf.com/auth/login' 504 Gateway Timeout Server port 80.
In my error.log :
Timeout when reading response from deamon process 'sqtf': /var/www/squashPy/src/squash_test_filter/sqtf/sqtf.wsgi
I added a python-home in my DeamonProcess. Increase Timeout doesn't change anything.
my 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>
my 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
a part of my /etc/hosts :
127.0.0.1 localhost
127.0.1.1 ubuntu
127.0.0.1 www.sqtf.com sqtf.com sqtf
# etc ...
a part of my /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
I solve the problem, if you use a flask factory, with create_app for example, you need to change this line from sqtf import app as application
in your .wsgi by this :
from sqtf import create_app
application=create_app()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.