【问题标题】:uWSGI: how to serve static files from root and an app from a sub directory?uWSGI:如何从根目录提供静态文件,从子目录提供应用程序?
【发布时间】:2015-12-12 20:11:20
【问题描述】:

我正在使用 Cloud 9 IDE 构建网站。我的目标是从站点根目录“/index.html”等提供静态网站。此站点中的内容将按计划重新生成(在此示例中为每天)。在“/admin”和“/api”端点,我想提供几个烧瓶应用程序。

因为这是在 Cloud 9 IDE 上构建的,所以我无权访问代理服务器配置。我必须使用 HTML 协议将所有内容提供给一个端口。 uWSGI 能够做到这一点。不过,我正在为我的配置文件苦苦挣扎:

#uwsgi.ini
[uwsgi]
static-index = index.html
static-map2 = /=/home/ubuntu/workspace/generated-site
static-map2 = /static=/home/ubuntu/workspace/static-assets

mount = /admin=admin.py
mount = /api=api.py
manage-script-name = true

master = true
processes = 5

socket=0.0.0.0:8080 
protocol=http

/admin/api 的请求按预期工作,返回结果或 404 错误。

//index.html 的请求都按预期返回generated-site/index.html。 对/no_exist.html 的请求按预期返回404 Not Found

我的问题是第二个static-map2。对/static/test.html 的请求返回404 Not Found(我在其中放置了一个html 文件进行测试)。

【问题讨论】:

  • 任何有兴趣的人应该可以看到一个演示应用程序@ide.c9.io/cstrutton/test-uwsgi
  • 对于可能需要这个的人,我想通了... /static/test.html 提供 static-assets/static/test.html

标签: python flask uwsgi cloud9-ide


【解决方案1】:

static-map2 保留 URL 的路径部分以供其搜索,以便将请求 /static/test.html 映射到文件

/home/ubuntu/workspace/static-assets/static/test.html

您很可能想要简单的static-map,它会在映射到文件系统之前从 URL 中删除路径。因此对/static/test.html 的请求将搜索该文件

/home/ubuntu/workspace/static-assets/test.html

【讨论】:

    猜你喜欢
    • 2017-08-31
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 2017-11-22
    • 2012-12-09
    • 2020-04-18
    • 1970-01-01
    相关资源
    最近更新 更多