【问题标题】:nginx config for ember.js/rails/passenger using history api使用历史 API 为 ember.js/rails/passenger 配置 nginx
【发布时间】:2015-03-18 21:19:26
【问题描述】:

我有一个 nginx 配置,无论用户访问哪个 URL,它都能正确地提供 index.html。例如,如果用户访问:myapp.example.com/foo/bar,nginx 正确地服务 index.html,以便 ember.js 可以处理 /foo/bar 路由。

但我还需要 nginx 将 /api 开头的 url 移交给我的 rails 应用程序。这是我当前的配置:

server {
  listen 80;
  server_name myapp.example.com;
  root /home/app/myapp/current/public;

  passenger_enabled on;
  passenger_user app;
  passenger_ruby /usr/bin/ruby2.2;

  location /api/ {
  }

  location / {
    try_files $uri $uri/ /index.html?/$request_uri;
  }

}

当 ember.js 发出任何 API 请求时,服务器(nginx,而不是 rails)返回 404。我应该在 location /api/ 部分中添加什么,或者我还应该更改什么?

【问题讨论】:

    标签: ember.js nginx passenger


    【解决方案1】:

    将乘客选项移动到位置 /api 部分似乎有效,如下所示:

    server {
      listen 80;
      server_name myapp.example.com;
      root /home/app/myapp/current/public;
    
      location /api/ {
        passenger_enabled on;
        passenger_user app;
        passenger_ruby /usr/bin/ruby2.2;
      }
    
      location / {
        try_files $uri $uri/ /index.html?/$request_uri;
      }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-04
      相关资源
      最近更新 更多