首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Nginx背后的React App开发

Nginx背后的React App开发
EN

Stack Overflow用户
提问于 2018-08-22 03:41:13
回答 1查看 1.2K关注 0票数 4

我有一个遗留的angular应用程序和一个新的react应用程序,我想通过nginx公开它们。

我有一个包含静态文件的产品nginx配置,但我试图让dev也能工作-使用热重载和webpack开发服务器。我已经让它正常工作了,但我意识到如果我能用/r/来限定react的范围,用/a/来限定angular应用程序的范围,那会更好。但是,使用下面的配置,每当我转到localhost/r/时,bundle.js都驻留在/static/中。有没有办法让react应用程序的/static/转到/r/static/

有没有更好的方法来做这件事?

代码语言:javascript
运行
复制
location /r {
  proxy_pass http://172.17.0.2:3000;
  proxy_set_header   X-Forwarded-For $remote_addr;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}
location /static/ {
  proxy_pass http://172.17.0.2:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}
location /sockjs-node/ {
  proxy_pass http://172.17.0.2:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}
EN

回答 1

Stack Overflow用户

发布于 2019-05-09 02:34:37

是的,有一个方法可以做到这一点:

代码语言:javascript
运行
复制
location /static/ {
  proxy_pass http:/172.17.0.2:3000/r/static/
  ...
}

查看the nginx.org docs for proxy_pass

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51955630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档