我正尝试在Ubuntu服务器上运行一个Flask应用程序,使用Apache、WSGI和Python3.8。
我开始跟踪Flask documentation的mod_wsgi。
为了设置这个项目,我从官方网站上下载了Flask tutorial。
我的根目录位于“/var/www/html/base/BE”,它看起来像:
├── activate_this.py
├── base_be.wsgi
├── be
│ ├── __init__.py
├── be.conf
├── myenv
└── src
├── __init__.py
├── MY_SRC_FILE.py
工厂函数**./be/init.py的内容如教程所述,只是一个包含所有初始化的“create_app”函数。
对于base_be.wsgi的内容,我遵循了SOq,它不使用我在myenv**上拥有的虚拟env。我的文件如下所示:
#/var/www/html/base/BE/myenv/bin/python
import sys
sys.path.insert(0, '/var/www/html/base/BE')
from be import create_app
application = create_app()
如果我按照建议在另一个SOq上添加activate_this.py,并在这个GitHub上共享代码:
activate_this = '/var/www/html/base/BE/myenv/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
我得到错误:
mod_wsgi (pid=34272): Failed to exec Python script file '/var/www/html/base/BE/base_be.wsgi'.
mod_wsgi (pid=34272): Exception occurred processing WSGI script '/var/www/html/base/BE/base_be.wsgi'.
Traceback (most recent call last):
File "/var/www/html/base/BE/base_be.wsgi", line 4, in <module>
exec(file_.read(), dict(__file__=activate_this))
File "<string>", line 28, in <module>
AttributeError: 'str' object has no attribute 'decode'
在my_application.conf上,我有:
<VirtualHost *:80>
ServerName api.base
WSGIDaemonProcess api.base python-path=/var/www/html/base/BE python-home=/var/www/html/base/BE/myenv
WSGIProcessGroup api.base
WSGIScriptAlias / /var/www/html/base/BE/base_be.wsgi
<Directory /var/www/html/base/BE/>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我已经将API.base添加到我的**/etc/hosts**中
每次我尝试使用以下命令访问应用程序时:API.base/auth/login,我刚刚得到错误500。
- 我怎样才能让我的应用程序运行和访问从“API.base/auth/login”?
- 我错过了什么?
- 到底发生了什么黑魔法?
1条答案
按热度按时间liwlm1x91#
你用的是什么flask版本?2. 0?
我不知道你想取得什么样成就
也许会把它评论掉
最后
你正在使用的github有一个注解(https://github.com/pypa/virtualenv/tree/main/src/virtualenv/activation)
不要使用过时的API
在Python的部分