【发布时间】:2015-12-23 22:20:24
【问题描述】:
我想将我的 Apache Web 服务器配置为同时为单页应用程序和 WSGI 进程提供服务。我可以使用此配置在/api 成功地为 WSGI 应用程序提供服务:
WSGIDaemonProcess myapp threads=5 user=apache
WSGIScriptAlias /api /var/www/html/myapp/setup/myapp.wsgi
因此,如果用户点击/api/things,我的 WSGI 应用程序(flask)中的 JSON 数据就会发送过来。
我的家index.html 文件(当用户点击/ 时提供)在包含以下内容时有效:
DocumentRoot /var/www/html/myapp/myappweb/public
但是,当用户访问任何不以 /api 开头的路由时,我希望我的 Apache Web 服务器提供 index.html。例如,如果用户点击 /things 或 /things/42 我希望 Apache 将它们发送到 index.html 而不是抛出 404。(我正在使用 redux-router 来处理客户端路径。)
我使用带有此标志的 node live-server 包在我的开发环境中工作:
live-server --entry-file=index.html
另外,我可以使用AliasMatch 强制所有以/things 开头的路由显示index.html:
AliasMatch "^/things(/.*)?$" /var/www/html/myapp/myappweb/public/index.html
但我真正想要的是一个AliasMatch 正则表达式,它强制所有路由(以/api/ 开头的任何内容除外)显示index.html。
【问题讨论】:
标签: regex apache single-page-application wsgi npm-live-server