![UWSGI 无法使用 nginx 和 flask 导入模块‘mysite’](https://linux22.com/image/615390/UWSGI%20%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8%20nginx%20%E5%92%8C%20flask%20%E5%AF%BC%E5%85%A5%E6%A8%A1%E5%9D%97%E2%80%98mysite%E2%80%99.png)
我是 uwsgi 和 nginx 的新手,我一直无法弄清楚为什么我会从 uwsgi 收到此错误:
ImportError: No module named mysite
unable to load app 0 (mountpoint='my_ipaddr|') (callable not found or import error)
这是我的 nginx 配置文件:
server {
listen 80;
server_name my_ipaddr;
location /static {
alias /var/www/mysite/static;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/mysite.sock;
uwsgi_param UWSGI_PYHOME /var/www/mysite/venv;
uwsgi_param UWSGI_CHDIR /var/www/mysite;
uwsgi_param UWSGI_MODULE app;
uwsgi_param UWSGI_CALLABLE app;
}
这是我的 uwsgi 的 mysite.ini:
[uwsgi]
vhost=true
socket=/tmp/mysite.sock
venv = /var/www/mysite/venv
这是我的app.py:
from flaskext.markdown import Markdown
from views import app
Markdown(app)
def main():
app.run()
if __name__ == '__main__':
main()
从命令行启动应用程序时,我可以使用 uwsgi 运行它,但我无法使用上述设置让它与 nginx 一起工作。
答案1
将设置从 nginx 移动到 uswgi 解决了我的问题:
我的站点.ini:
[uwsgi]
vhost=true
socket=/tmp/mysite.sock
venv = /var/www/mysite/venv
chdir = /var/www/mysite
module = app
callable = app
nginx 配置文件:
server {
listen 80;
server_name my_ipaddr;
location /static {
alias /var/www/mysite/static;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/mysite.sock;
}