【发布时间】:2017-06-30 02:07:06
【问题描述】:
我正在尝试设置本地 react 和 rails 环境。我的 React 应用程序目前托管在 http://localhost:8080,我的 rails 应用程序托管在 http://localhost:3000。我希望这两个都从同一个网址提供,例如http://localhost:9999。
基本原理如下:
http {
server {
listen 9999;
location / {
proxy_pass http://localhost:8080/;
}
location /api {
proxy_pass http://localhost:3000/;
}
}
}
问题是在地址栏中粘贴/ 以外的路由不起作用——这是一个常见问题。
因此,一个常见的答案是将location / 规则更改为如下所示:
location / {
try_files $uri $uri/ /client/index.html
}
但是,这给了我错误:
在内部重定向到“/client/index.html”时重写或内部重定向循环
这是有道理的,但我不知道如何绕过它。
我的目录结构:
root/
- app/ (rails app)
- client/ (react app, currently served by webpack-dev-server)
- index.html
【问题讨论】:
标签: ruby-on-rails reactjs nginx react-router