在uWSGI上访问Flask-Admin时出现404 Not Found
我刚开始学习网页编程,所以我觉得我的配置中可能缺少了什么超级简单的东西,希望你们能帮我!(还有,请原谅我的英语 - 哈哈)
事情是这样的:我在用Flask做一个小应用,所有功能都正常。特别是我在玩Flask-Admin:
123.45.67.8:8080/admin/
这个地址能正常显示我的管理面板……但是一旦我从内置服务器切换到nginx/uWSGI,网址
www.mywebsite.com/admin/
就出现404错误……不过其他部分都能正常工作!
我用以下命令启动uWSGI:uwsgi --ini /path/to/myweb_uwsgi.ini
myweb_uwsgi.ini
[uwsgi]
#application's base folder
base = /var/www/myweb
#python module to import
app = myweb
module = %(app)
home = %(base)/venv
pythonpath = %(base)
#socket file's location
socket = /var/www/myweb/%n.sock
#permissions for the socket file
chmod-socket = 666
#the variable that holds a flask application inside the module imported at line #6
callable = app
#location of log files
logto = /var/log/uwsgi/%n.log
这是我的nginx配置文件:
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / { try_files $uri @yourapplication; }
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/var/www/myweb/myweb_uwsgi.sock;
}
}
我很确定我在uWSGI的ini文件中缺少了什么,但我就是搞不清楚……
1 个回答
1
出现这个问题的原因是应用程序没有被正确初始化。你可以尝试把 admin.Admin() 的初始化代码移出主函数,并且添加视图。这听起来有点傻,但文档里没有提到这一点。