首页 > 解决方案 > Nginx 返回一个由四个别名匹配的文件

问题描述

我正在尝试提供一个react appwith nginx,并且浏览器下载build/index.html由别名/app/room/main,/app/room/create等访问(这是必要的,因为应用程序的状态取决于 URL)。如何在没有浏览器下载的情况下通过多个别名来提供这个文件。

标签: nginxstatic-files

解决方案


使用 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;
    }



推荐阅读