如何配置我的 Nginx 服务器以使用子文件夹中的 React 应用程序?
How do I configure my Nginx server to work with a React app in a subfolder?
我正在尝试在我的 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。
我正在尝试在我的 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。