nginx - Nginx 返回一个由四个别名匹配的文件
问题描述
我正在尝试提供一个react app
with nginx
,并且浏览器下载build/index.html
由别名/app/room/main
,/app/room/create
等访问(这是必要的,因为应用程序的状态取决于 URL)。如何在没有浏览器下载的情况下通过多个别名来提供这个文件。
解决方案
使用 nginx 服务 react 应用程序。
location /payments/room/ {
# serve static files from build
alias /path/to/build/;
}
location ~ ^/payments/room/(room-create-pick|settings|main|new-payment) {
# these four links should be handled by my react app
# (the index.html) should be returned
alias /path/to/build/;
try_files index.html =404;
}
推荐阅读
- django - 将 Django 项目从 sqlite 更新到 Postgres:未指定 manage.py,ModuleNotFoundError
- reactjs - 如何在不提交的情况下访问 formik 字段的当前值?
- c# - 无法将数据直接拉到视图 MVC Claims Identity
- sql - Big Query 中的 LEFT JOIN 充当 RIGHT JOIN
- c# - 将 SQL 服务器查询转换为 EF Core LINQ
- spring - Spring 组件依赖于从 application.properties 加载 props 但未加载 props 的配置
- image - 如何批处理色度键照片(屏蔽绿屏)
- css - Ant design v4中如何动态切换主题?
- android - 具有可聚焦元素的嵌套 RecyclerViews java.lang.IllegalArgumentException:参数必须是此视图的后代
- c# - C# Win 表单无法打开