【问题标题】:uWSGI routing rule is overriding static filesuWSGI 路由规则覆盖静态文件
【发布时间】:2015-10-26 13:35:46
【问题描述】:

我想要以下路由行为:

  • webapp/static/ 中存在的任何路径都应路由到该文件
  • 任何其他不以/auth/api 开头的路径都应该路由到webapp/static/pages/index.html
  • 将剩余的请求路由到我的 uwsgi 应用程序。

我有以下 uWSGI 配置:

[uwsgi]
http-socket = :$(PORT)
master = true
processes = 4
die-on-term = true
module = webapp:app
memory-report = true

;HSTS
route-host = ^localhost:(?:[0-9]+)$ goto:localhost
route-if-not = equal:${HTTP_X_FORWARDED_PROTO};https redirect-permanent:https://${HTTP_HOST}${REQUEST_URI}
route-if = equal:${HTTP_X_FORWARDED_PROTO};https addheader:Strict-Transport-Security: max-age=31536000; preload

route-label = localhost
check-static = %v/webapp/static/
route = ^(/?|/(?!(auth.*|api.*))(.*))$ static:%v/webapp/static/pages/index.html

问题是最终路由规则覆盖了静态文件处理程序,即使我更改了它们的顺序。以前,我使用正则表达式 ^/?$ 仅将请求发送到 / 到索引页面,这有效完美,所以它必须与正则表达式的工作方式有关。

【问题讨论】:

    标签: regex configuration routing uwsgi ini


    【解决方案1】:

    可能在正则表达式之后评估静态规则。您使用的正则表达式也匹配 /webapp/static 路径,因此我们也需要排除该路径。

    尝试像这样修改正则表达式规则:

    # I removed also unused matching groups and append '/' to the exclude path
    route = ^(?:/?|/(?!(?:auth|api|webapp/static)/).*)$ static:%v/webapp/static/pages/index.html
    

    【讨论】:

      猜你喜欢
      • 2020-07-11
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      相关资源
      最近更新 更多