2017-10-19 30 views
2

我想在我的Nginx服务器的子文件夹中部署一个React应用程序。如何配置我的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.. 
} 

这没有奏效。我需要更改什么来修复我的子文件夹路由?

+0

你可以将反应路由器上的基名设置为'/ reactApp'吗? https://reacttraining.com/react-router/web/api/BrowserRouter/basename-string –

回答

3

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

+0

这工作。谢谢! – shane

相关问题