部署 请教关于同一个 domain 下面部署 2 个应用 (静态和动态)

1272729223 · 2016年05月09日 · 最后由 1272729223 回复于 2016年05月11日 · 2018 次阅读

现在我的情况是:

首页、文档等页面是用jekyll生成的静态页面 - APP1;其余的是一个用node跑的 JavaScript SPA 应用 - APP2。然后想把两个应用部署在同一个域名下。e.g. http://example.com

现在,我想的是用nginx来部署这两个应用。我搜了一些教程,只是告诉如何部署两个应用不同域名端口下。但是我想要的结果可能跟它还是有一点区别。

因为APP1的访问路径是:

  • example.com/
  • example.com/documentations
  • example.com/documentations/1
  • ...

APP2的路径会是:

  • example.com/#/login
  • example.com/#/signup
  • example.com/#/dashboard
  • ...

这个应该可以

location /app2{
  proxy_pass http://app2;
}
location =/ {
  app1
}
location /documentations{
  proxy_pass http://app1;
}

官方 Guides 里面就提到了如何将 Rails 部署在一个子目录下面的方式:

http://guides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root

config.relative_url_root = "/app1"

https://ruby-china.org/topics/28929 我之前的方法(nginx 直接配置的方法没成功就没试了)

#3 楼 @linyunjiang 已经配好,不过后续还要稍微深入些了解下 nginx。我是把应用跑在 node 上,然后 nginx 代理的。

#3 楼 @linyunjiang 对了,还用了子域名。

  • http://domain.com 管理 jekyll 应用(如:首页、文档页面等)
  • http://app.domain.com 管理 JS 应用 (业务方面)
需要 登录 后方可回复, 如果你还没有账号请 注册新账号