【问题标题】:nginx: remove path from proxy_pass on named locationnginx:从命名位置的proxy_pass中删除路径
【发布时间】:2016-02-07 01:41:18
【问题描述】:

我有这个 nginx 配置来为 rails 应用程序提供服务:

  location ^~ /api/ {
    alias /srv/www/rails/public/;
    try_files $uri @unicorn;
  }

  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://127.0.0.1:2007;
  }

我想在将 /api/ 传递给 rails 应用程序之前从路径的开头删除它,但由于它是一个命名位置,我不能在 proxy_pass 指令的末尾添加“/”,我该如何删除 /api/在将请求传递给 Rails 之前?

【问题讨论】:

    标签: ruby-on-rails nginx


    【解决方案1】:

    用途:

    location @unicorn {
        rewrite ^/api(.*)$ $1 break;
        ...
    }
    

    详情请见this document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-21
      • 2014-10-17
      • 2016-01-18
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多