0

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.

3
  • 1
    Why do you have three different root directives, all pointing to different directories? Fix that first, and I expect it will resolve your problem. Aug 20, 2015 at 0:50
  • I thought that was how you were supposed to change directories to tell nginx where to look for static files. Took that from their website. nginx.org/en/docs/beginners_guide.html#static Aug 20, 2015 at 17:09
  • @MichaelHampton I went ahead and tried your suggestion. I changed the server root to /srv/www/cc/app and removed the other two. Everything which was working continues to work, and the root / location on the site still returns 403 :( Aug 20, 2015 at 20:32

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .