1

Basically I have a single views.py with all my routes in it. They all work great on production except for one... the homepage at the root location '/'

from views.py

@app.route('/', methods = ['GET'])
def homepage():

    return render_template("/client/homepage.html")

@app.route('/admin/', methods = ['GET'])
@login_required
def admin():

    submissions = Campaign.query.all()

    return render_template("admin.html",
        title = 'Admin',
        submissions = submissions)

Instead of displaying the page, I get a 403 forbidden message.

From the nginx logs:

directory index of "/srv/www/cc/app/" is forbidden

Anyone know what's wrong with my flask route which would cause this change in behavior from '/admin/' to '/'?

EDIT

I've found multiple posts online about this issue, and one of the suggestions was to turn autoindex on within nginx. I did this, and it gave me a directory of the root location... which makes me think that the issue may be that nginx simply isn't passing the request to uwsgi. But i'm not sure what to do about that.

5
  • 1
    Almost certainly a user permissions error for nginx. make sure that www-data can read that directory
    – reptilicus
    Aug 21, 2015 at 17:28
  • @reptilicus I saw references to permissions online so i took my whole /srv/www/cc/ tree and made all files 644 and all directories 775. They're also all owned www-data and have the group www-data Aug 21, 2015 at 18:28
  • 1
    @Chockomonkey If you changed the permissions directly on the /srv/www/cc/ path, you also need to ensure you have the same or more permissive permissions higher up on the path for /srv and /srv/www. See: unix.stackexchange.com/questions/13858/…
    – chishaku
    Aug 21, 2015 at 20:00
  • @chishaku thanks for the suggestion. I went ahead and applied 755 to all directories from /srv onward, but still no dice. Worth a shot though. Aug 21, 2015 at 20:13
  • @Chockomonkey Also double check that you set permissions recursively so that ./app/templates/client would have the same permissions. Just mentioning this since one difference between your two routes is that the homepage template is one level deeper in the path.
    – chishaku
    Aug 21, 2015 at 20:16

2 Answers 2

2

Turned out it was the way I'd written my nginx.conf.

After pouring over the documentation on try_files, It became apparent to me that i needed to simply add

error_page 403 = @cc;

to my location block. The reason being apparently that the try_files directive will try to match each request directly in the order in which they're listed, so in my case my location @cc was the last. Nginx was finding a match for / and only / based on the $uri, and was then trying to display the page accordingly. Since I have all my uwsgi stuff in my @cc location, I had to redirect the request there with the error_page 403 = @cc; bit.

Here's the final product:

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;
        error_page 403 = @cc;
    }
    location /uploads/ {
        expires max;
    }
    location /static/ {
        expires max;
    }
    location @cc {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
    }
}
0

I have also faced the same issue. In my case unfortunately yarn-build has failed and the build folder has nothing!. So, re-run the yarn-build and it solved the issue

It may helpful for someone who facing this kind of issue.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.