我是 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;
}