Question

I decided to use Python as a primary language on my starting up website. I'm pretty sure that uWSGI and Bottle framework work perfect together. I'm a little bit worry that they will serve static files slowly ( I experienced this problem in NodeJS ). Is it preferably to specify multiple uWSGI apps and point them to different directories that don't contain static files? Will Nginx serve static files faster?

ROOT/
|--assets/
|----some.css
|----and_image.png
|--robots.txt

sign_in/
|--[application related files here]
sign_up/
|--[application related files here]

Web server's root is ROOT and application's and directories that contain files of application are outside the web server's root.

I suppose this will be better

location /sign-in {
    uwsgi_pass      unix:///run/uwsgi/app/sign-in/sign-in.co.socket;
    include         uwsgi_params;
    uwsgi_param     UWSGI_SCHEME $scheme;
    uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
}


location /sign-up {
    uwsgi_pass      unix:///run/uwsgi/app/sign-up/sign-up.co.socket;
    include         uwsgi_params;
    uwsgi_param     UWSGI_SCHEME $scheme;
    uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
}

than this:

location / {
    uwsgi_pass      unix:///run/uwsgi/app/whole-website/whole-website.co.socket;
    include         uwsgi_params;
    uwsgi_param     UWSGI_SCHEME $scheme;
    uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
}

Is it really better? Or in this case uWSGI won't serve static files?

Was it helpful?

Solution

You want nginx to serve your static files. Given they are static, there's no logic required to serve them, unlike your templates/views in bottle. So its better for static file requests to never have to hit python. And its really easy to set up in nginx!

Inside your server block just add:

location /assets/ {
  alias pathtoyourproject/ROOT/assets/;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top