【问题标题】:How to deploy nextjs into a directory which is not a root directory如何将nextjs部署到不是根目录的目录中
【发布时间】:2023-03-25 17:21:01
【问题描述】:

最近我学习了一些关于 nextjs 的知识,因为我想使用 React 制作一个对 SEO 友好的网站。在我遇到问题之前,一切看起来都很棒。

这是关于如何将 nextjs 应用程序部署到非根目录的目录中,例如“/next”。我对 nextjs 使用了一个简单的配置,使用默认节点服务器监听 3000 端口,然后使用 nginx 进行反向。

next.config 看起来像:

nginx 配置:

当我访问localhost:8080/next时,我得到了nextjs提供的404页面,并且css或js也是404。似乎nextjs或nginx的配置错误。

【问题讨论】:

    标签: node.js nginx webpack next.js


    【解决方案1】:

    您当前的配置告诉 nginx 将 url 一对一映射,这意味着 /next/what-ever 将被映射到 http://localhost:3000/next/what-ever

    要解决这个问题,您需要添加一个额外的斜线。

    server {
      ...
      location /next/ {
        proxy_pass http://localhost:3000/ // <----  this last slash tells to drop the prefix
      }
    }
    

    更多信息请阅读https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/#passing-a-request-to-a-proxied-server

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      • 2015-10-25
      • 2013-08-07
      • 2012-07-18
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多