nginx - 为多个 React 应用程序配置 Nginx
问题描述
我想在同一台服务器上使用 Nginx 提供两个 React 应用程序。在阅读了 Nginx 的文档并研究了多个网站之后,我仍然无法同时提供多个应用程序。我展示的配置在 /etc/nginx/conf.d/myserver.conf 中的一个文件中,我将展示两个示例,一个仅用于一个可以运行的应用程序,另一个用于两个应用程序,但没有吨。
此示例仅使用一个 React 应用程序(我通过http://myserver/foo访问其中)有效:
server {
listen 80;
server_name myserver;
root /var/www/html/foo/build;
location /foo {
try_files $uri $uri/ /index.html;
}
}
这个例子不起作用,我想在http://myserver/foo和http://myserver/bar上提供两个应用程序):
server {
listen 80;
server_name myserver;
location /foo {
root /var/www/html/foo/build;
try_files $uri $uri/ /index.html;
}
location /bar {
root /var/www/html/bar/build;
try_files $uri $uri/ /index.html;
}
}
我尝试过其他配置,但我发布了这个配置,因为我相信它更好地说明了我尝试做的事情。
解决方案
尝试
server {
listen 80;
server_name myserver;
location /foo {
alias /var/www/html/foo/build;
try_files $uri $uri/ /index.html;
}
location /bar {
alias /var/www/html/bar/build;
try_files $uri $uri/ /index.html;
}
}
推荐阅读
- python - 在 Django 中使用 selenium 进行通道测试会引发错误消息
- ios - 在 UITabBarController 中的选项卡更改后,GADBannerView 中的 AdMob 视频广告继续使用 CPU
- android - Textview 从下一个开始查看一行并返回到下一个开始
- c# - ASP.NET Core 2.1 Razor 表单,帖子未到达控制器
- sql - 将前导零附加到字段
- r - 在 R 中使用 RODBC 创建循环 SQL QUERY
- android - 在片段中,使用 Parcelable 实现恢复包含另一个对象列表的对象
- windows - 无法在 Windows 上使用 LLVM 库
- firebase - Firebase 安全规则从另一个节点获取值并将其与 auth.uid 进行比较
- javascript - 在 reactjs 中编辑数组