I've seen other posts say that either file permissions or the lack of an index directive are the cause. However, my Flask application does not have an index file at all, and most of the site works like a charm.
nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 5M;
root /srv/www/cc/app;
location / {
try_files $uri $uri/ @cc;
}
location /uploads/ {
# root /srv/www/cc/app;
expires max;
}
location /static/ {
# root /srv/www/cc/app;
expires max;
}
location @cc {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
}
snippet from views.py
@app.route('/', methods = ['GET'])
def client():
return render_template("/client/index.html")
#-----------------CLIENT ABOVE, ADMIN BELOW------------------#
@app.route('/admin/', methods = ['GET'])
@login_required
def admin():
submissions = Campaign.query.all()
return render_template("admin.html",
title = 'Admin',
submissions = submissions)
So I basically have a single views.py with a ton of routes. All the ones which are /admin/ work like a charm, but the one which is just /, doesn't.
As I said, I do not have an index. I tried setting the index directive in nginx.conf to "app" as that's where the magic happens... but no dice.
Here's my file structure:
/cc/
app/
__init__.py
views.py
etc
uploads/
static/
config.py
From the nginx logs:
directory index of "/srv/www/cc/app/" is forbidden
I've found similar issues from other folks online and I've verified that nginx runs with user www-data, and that this use is owner of the directory.
So apparently I didn't fully understand how try_files worked.
After reading up on it, it was not finding a match for any request that wasn't '/' but it WAS matching to '/' and trying to list the directory. Once i added error_page 403 = @cc into the root location block, it redirects correctly to my cc location and displays the homepage.