我有一个简单的 nginx 配置来为我的 React 应用程序提供服务:
server {
listen 80;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
我有路线/和login。localhost/当我从 React-Router 转到通过React-Router时,一切正常localhost/login。但是当我localhost/login在浏览器中输入内容时,出现 404 错误。
确切地说,因为localhost/login我进入"/usr/share/nginx/html/login" failed (2: No such file or directory)了 nginx 控制台。因为localhost/login/我得到"/usr/share/nginx/html/login/index.html" is not found (2: No such file or directory)
我不明白为什么 nginx 一直在寻找index.htmlin/usr/share/nginx/html/login/而不是/usr/share/nginx/html/. 有什么想法我做错了吗?