【问题标题】:React app and Next js under same Production fe urlReact app 和 Next js 在同一个 Production fe url 下
【发布时间】:2021-10-30 22:45:06
【问题描述】:

我有两个项目,一个是在提供静态页面的下一个 js 中完成的,另一个是在提供逻辑和身份验证部分的 react 中。 现在我想知道有没有办法在同一个 URL 中为这两个项目提供服务 例如:

www.charan.com/blog //is coming from nextjs
www.charan.com //is coming from nextjs
www.charan.com/protected //is coming from react app
www.charan.com/login //is coming from react app

【问题讨论】:

    标签: reactjs next.js


    【解决方案1】:

    是的,有!有无数的选择,但我会通过将nginx 设置为反向代理来实现这一点。有一个问题涉及此here

    nginx 仅与 nextjs 一起使用时,您可以在配置文件中定义另一个 location(或多个),然后将其转发到另一个在本地端口上为您的 react 页面提供服务的网络服务器,或者让 nginx直接提供index.html 文件:

    location /protected {
            try_files $uri /react-app-folder/index.html; # redirect all request to index.html
        }
    

    这需要一些时间,因为您需要确保 JS 和 CSS 文件是从正确的目录提供的,但这应该会为您提供足够的信息来完成此操作,并提供一些新的 Google 关键字供您查找。

    【讨论】:

    • 感谢您的回答,如果我不使用 nginx,如果我使用的是数字海洋或 aws 平台,我该如何实现这一目标
    猜你喜欢
    • 2019-06-18
    • 2020-09-02
    • 2022-12-05
    • 2019-04-27
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    相关资源
    最近更新 更多