如何配置我的Nginx服务器以使用子文件夹中的React应用程序?

sha*_*ane 6 nginx reactjs react-router ubuntu-16.04

我试图在我的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..
}
Run Code Online (Sandbox Code Playgroud)

这没效果.我需要更改什么才能修复子文件夹路由?

Ric*_*ith 11

try_files语句的最后一个组件应该是URI.假设您的index.html文件位于/var/www/reactApp子文件夹下,您应该使用:

location /reactApp {
    root /var/www;
    index  index.html;
    try_files $uri $uri/ /reactApp/index.html;
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅此文