uWSGI 路由规则覆盖静态文件
uWSGI routing rule is overriding static files
我想要以下路线行为:
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
问题是最终的路由规则覆盖了静态文件处理程序,即使我改变了它们的顺序。以前,我使用正则表达式 ^/?$
只将请求发送到 /
到索引页面,运行良好,所以它一定与正则表达式的工作方式有关。
可能在正则表达式规则之后评估静态规则。您使用的正则表达式也匹配 /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
我想要以下路线行为:
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
问题是最终的路由规则覆盖了静态文件处理程序,即使我改变了它们的顺序。以前,我使用正则表达式 ^/?$
只将请求发送到 /
到索引页面,运行良好,所以它一定与正则表达式的工作方式有关。
可能在正则表达式规则之后评估静态规则。您使用的正则表达式也匹配 /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