【问题标题】:(nginx + uWSGI + Bottle) Serve static Files(nginx + uWSGI + Bottle) 提供静态文件
【发布时间】:2013-02-19 21:04:03
【问题描述】:

我决定在我的启动网站上使用 Python 作为主要语言。我很确定 uWSGI 和 Bottle 框架可以完美地协同工作。我有点担心他们会慢慢地提供静态文件(我在 NodeJS 中遇到过这个问题)。是否最好指定多个 uWSGI 应用程序并将它们指向不包含静态文件的不同目录? Nginx 会更快地提供静态文件吗?

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

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

Web 服务器的根目录是ROOT,应用程序和包含应用程序文件的目录位于 Web 服务器的根目录之外。

我想这样会更好

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;
}

比这个:

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;
}

真的更好吗?或者在这种情况下 uWSGI 不会提供静态文件?

【问题讨论】:

    标签: python nginx uwsgi bottle static-files


    【解决方案1】:

    您希望 nginx 为您的静态文件提供服务。鉴于它们是静态的,与瓶中的模板/视图不同,它们不需要任何逻辑来提供服务。因此,静态文件请求永远不必打 python 更好。而且在 nginx 中设置真的很容易!

    在你的服务器块内添加:

    location /assets/ {
      alias pathtoyourproject/ROOT/assets/;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 1970-01-01
      • 2017-06-05
      • 2012-05-15
      • 2021-09-03
      • 2018-05-18
      相关资源
      最近更新 更多