【问题标题】:React router with nginx is throwing 404 page not found使用 nginx 的反应路由器抛出 404 页面未找到
【发布时间】:2019-11-11 08:39:18
【问题描述】:

当我们尝试像localhost/page1这样的直接网址时,nginx 会抛出 404 页面未找到。

我们正在使用 react-router、webpack 和 nginx。

在 nginx 配置中我们尝试过

 location /{
    try_files $uri index.html;
}
 location /{
    try_files $uri $uri/ =404;
}
 location /{
    try_files $uri $uri/ index.html;
}

这是我的 webpack 配置

 devServer: {
    historyApiFallback: true,
    host : '0.0.0.0'
  },

但没有任何效果, 我在这里有什么遗漏吗?

【问题讨论】:

    标签: nginx webpack react-router


    【解决方案1】:

    试试这个

    location / {
      try_files $uri /index.html;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 2017-08-13
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 2018-05-03
      • 2020-12-13
      相关资源
      最近更新 更多