如何配置Nginx服务器以与子文件夹中的React应用一起使用? [英] How do I configure my Nginx server to work with a React app in a subfolder?
本文介绍了如何配置Nginx服务器以与子文件夹中的React应用一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的Nginx服务器上的子文件夹中部署React应用程序.
I am trying to deploy a React application in a subfolder on my Nginx server.
此React应用的位置的结构类似于:www.example.com/reactApp.
The location of this React app is structured like: www.example.com/reactApp.
我试图像这样设置当前的nginx.conf:
I tried to set up my current nginx.conf like so:
server {
..other configs..
location /reactApp {
root /var/www;
index reactApp/index.html;
try_files $uri $uri/ /index.html;
}
..other configs..
}
这没有用.我需要更改什么来修复子文件夹路由?
This has not worked. What do I need to change to fix my subfolder routing?
推荐答案
try_files
语句的最后一个组件应该是URI.假设您的index.html
文件位于/var/www/reactApp
子文件夹下,则应使用:
The last component of the try_files
statement should be a URI. Assuming that your index.html
file is located under the /var/www/reactApp
subfolder, you should use:
location /reactApp {
root /var/www;
index index.html;
try_files $uri $uri/ /reactApp/index.html;
}
有关更多信息,请参见此文档.
See this document for more.
这篇关于如何配置Nginx服务器以与子文件夹中的React应用一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文