【问题标题】:Apache serve single page application alongside WSGI process with AliasMatchApache 使用 AliasMatch 与 WSGI 进程一起提供单页应用程序
【发布时间】: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


    【解决方案1】:

    知道了!

    RewriteRule ^((?!\/[api|lib]).)*$ /var/www/html/myapp/myappweb/public/index.html
    

    我需要排除 api 目录和 lib 目录(我的 js/css 文件所在的位置)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 2011-12-08
      相关资源
      最近更新 更多