Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using nginx as a proxy to a couple of flask apps, with uwsgi as the middleware. Here's my nginx config for a test app.


server {
    listen      80;
    server_name test.myapp.com www.test.myapp.com;
    charset     utf-8;
    client_max_body_size 250M;
    location / { try_files $uri @testapp; }

location @testapp {
    include uwsgi_params;
    uwsgi_pass unix:/tmp/testapp_uwsgi.sock;
}

location /forecaster/components/ {
    alias /opt/test/client/app/components/;
}

}

I'm pretty sure that nginx is not actually serving the static files though, even if I comment out the location block, the files are getting served from something. I see 200's in the nginx log, as well as 200's in the uWsgi logs. How can you tell which one is serving the static files? I suppose that the flask app could be serving them as well?

/opt/test/client/app/components/ certainly exists, and is readable to others. Is there some way to force uwsgi NOT to handle these requests?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You do need a location. But that's not why nginx isn't serving your static files.

The problem is you forgot to specify a root directive in your server block. So nginx uses its compiled-in default, which is system-dependent and almost certainly isn't where your web app is located. Thus, all requests, including for static files, go upstream to uWSGI.

To fix the problem, set a root directive pointing to your app's static resources.

server {
    root /srv/www/testapp;

Or if you only have static files in subdirectories, you can specify then with location and alias as shown in the uWSGI documentation.

location /static {
    alias /srv/www/testapp/static;
}
share|improve this answer
    
yup, added root to server description and all is well. Requests for static files are no longer showing up in uwsgi logs, only data routes that hit the python app are. Gracias. –  reptilicus Jan 27 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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