ruby-on-rails - nginx:从指定位置的 proxy_pass 中删除路径

标签 ruby-on-rails nginx

我有这个 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 之前?

最佳答案

使用:

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

参见 this document了解详情。

关于ruby-on-rails - nginx:从指定位置的 proxy_pass 中删除路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35243049/

相关文章:

mysql - ThinkingSphinx::SphinxError(未知的 MySQL 错误)

javascript - 如何将带有工具提示的html外部链接更改为rails中的link_to

nginx - CentOS 上的 502 错误网关 mvc 核心应用程序

php - Laravel - 发布请求空字段

networking - 主机无法访问Docker容器

drupal - 使用两个容器通过 docker 设置 drupal? nginx 和 mariadb

ruby-on-rails - 我可以通过 Rails 代码设置不同的 SSL 证书子域吗?

ruby-on-rails - 如何让 capybara 找到快速出现和消失的元素(加载微调器)

javascript - rails : How to escape_javascript with client-side AJAX request

javascript - 如何在使用 Nginx 服务器发送每个请求之前修改 build 文件夹中的 index.html 文件?