Nip*_*arg 4 nginx reactjs react-router
我有一个 React 前端应用程序,它使用 react-router 创建不同的路由。在开发服务器上它工作正常,但是当我构建项目时,它在直接使用不同的路由访问它时给了我 404。网站完美打开xyz.net。当我尝试使用xyz.net/login.
这是我的 nginx 配置文件
server {
listen 80;
server_name xyz.net www.xyz.net;
root /root/frontend/react/build/;
index index.html;
location /api/ {
include proxy_params;
proxy_pass http://localhost:8000/;
}
Run Code Online (Sandbox Code Playgroud)
}
小智 5
当我遇到这个问题时,这对我有用:
location / {
#...
try_files $uri $uri/ /index.html$is_args$args;
#...
}
Run Code Online (Sandbox Code Playgroud)
但是,我在其他项目中遇到了使用*.ejs模板进行开发构建的错误,以及*.html使用 webpack 进行生产构建的插件。我在这里找到的答案:
希望有帮助。
| 归档时间: |
|
| 查看次数: |
4745 次 |
| 最近记录: |