Search code examples
pythonnginxflaskuwsgiflask-admin

404 Not Found when trying to access Flask-Admin on uWSGI


i'm a newbie in web programming, so i'm expecting to be missing a super simple thing in my configuration, hoping you can help me! (Also forgive my english - heh)

So here's the thing: I'm on my little app on Flask, and everything works. In particular i'm messing around with Flask-Admin:

123.45.67.8:8080/admin/

returns my working admin panel... As soon as i switch from the built in server to nginx/uWSGI the url

www.mywebsite.com/admin/

gives me a 404...but only for the Flask-Admin part, everything else works perfectly!

i start uWSGI with the following command 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

and this is my nginx .conf file

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

I'm pretty sure i'm missing something in uWSGI ini file, but I can't figure it out...


Solution

  • The reason this happens is that the app isn't initialized. Try moving the admin.Admin() initialization block away from the main function as well as adding the views. This is silly but not in the docs.