我正在尝试在 Nginx 服务器上的子文件夹中部署 React 应用程序。
此 React 应用程序的位置结构如下:www.example.com/reactApp。
我尝试像这样设置当前的 nginx.conf:
server {
..other configs..
location /reactApp {
root /var/www;
index reactApp/index.html;
try_files $uri $uri/ /index.html;
}
..other configs..
}
这没有用。我需要更改什么来修复我的子文件夹路由?
请您参考如下方法:
try_files 语句的最后一个组成部分应该是 URI。假设您的 index.html 文件位于 /var/www/reactApp 子文件夹下,您应该使用:
location /reactApp {
root /var/www;
index index.html;
try_files $uri $uri/ /reactApp/index.html;
}
参见this document了解更多。






