我的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
是您项目的根文件夹。