在debian 8.11上为flask 1.0.3配置Apache/2.4.10 mod_wsgi和virtualenv



我的apache配置文件有:

<VirtualHost *:80> 
ServerName localhost
WSGIDaemonProcess tasks4 python-path=/home/user1/Projects/tasks/tasks/tasks/wsgi.py:/home/user1/env_rt_dms:/home/user1/env_rt_dms/lib/python3.6/site-packages
WSGIScriptAlias / /home/user1/Projects/tasks/tasks/tasks/wsgi.py
WSGIPassAuthorization On
Alias /rt1 /home/user1/Projects/tasks/tasks/tasks/static/
<Directory /home/user1/Projects/tasks/tasks>
DirectoryIndex index.html
WSGIProcessGroup tasks4
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
</Directory>
</VirtualHost>

wsgi文件:

#! /home/user1/env_rt_dms/bin
import sys, os
activate_this = '/home/user1/env_rt_dms/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
os.environ['DB_URL']="postgresql://usernm:passwd1@localhost:5432/my_db"
from tasks import app as application
application.secret_key = 'x04xf5\VN:xb7xb9xcax95xa3m!4@x17xfcgxe5xe2qx05'

激活apache web服务器后的浏览器url:http://localhost/rt1给出404错误

apache日志显示:mod_wsgi:Compiled for Python/3.4.2作为警告。请让我知道我需要修复什么才能使此配置正常工作?

应设置WSGIDaemonProcess指令的python-home选项。

激活在终端中安装mod_wsgi的虚拟环境。

运行命令,终端中的python -c "import sys; print(sys.prefix)",复制输出,并将其设置为python-home选项。

WSGIDaemonProcess tasks4 python-path=/home/user1/Projects/tasks/tasks/tasks python-home=<sys_prefix_value_in_virtual_env>

删除wsgi.py模块中虚拟环境的手动激活。

#!/usr/bin/env python
import sys, os
os.environ['DB_URL']="postgresql://usernm:passwd1@localhost:5432/my_db"
from tasks import app as application
application.secret_key = 'x04xf5\VN:xb7xb9xcax95xa3m!4@x17xfcgxe5xe2qx05'

查看python-path选项,并确保/home/user1/Project/tasks/tasks/tasks是您项目的根文件夹。

最新更新