ruby-on-rails - 反向代理未将查询字符串传递给应用程序
问题描述
我创建了一个 Rails 应用程序,该应用程序部署到我的 Vultr 服务器的子目录中。不知何故,后端不考虑 GET 参数。例如,来自ForestAdmin API的调用不会读取 GET 参数(请参阅此处的问题)。此外,我的搜索页面没有接收到 GET 参数,例如在生产中的这个搜索查询,我得到以下日志:
如您所见,在标题中,« » 是空白的,因为它应该显示 q 参数。
我的 Rails 应用程序配置似乎正确,所以我猜这是服务器配置问题。
这是我的路线:
Rails.application.routes.draw do
scope 'dictionnaire' do
mount ForestLiana::Engine => '/forest'
root to: "home#index"
resources :words, path: "definition", param: :slug
post '/search', to: 'words#search'
get '/recherche', to: 'words#search_page', as: 'recherche'
get '/:letter', to: 'words#alphabet_page', param: :letter, as: "alphabetic_page"
post '/api/get_synonyms', to: 'api#get_synonyms'
end
end
这是我的 nginx 配置:
location @ruby-app {
# rewrite ^/dictionnaire-app(.*) $1 break;
rewrite ^/dictionnaire$ /dictionnaire/ permanent;
rewrite ^/dictionnaire/definition-(.*) /dictionnaire/definition/$1 permanent;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://127.0.0.1:3000$uri;
#proxy_set_header X-Forwarded-Proto https;
}
location ~ /dictionnaire(.*)$ {
alias /opt/dictionnaire-app/public;
try_files $1 @ruby-app;
}
和
location /dictionnaire {
try_files $uri $uri/ /dictionnaire/index.php?q=$uri&$args;
}
知道阻止参数传递的问题可能是什么吗?
解决方案
问题
proxy_pass 没有将查询字符串转发到 Rails 应用程序
解决方案
添加$is_args
到您的代理通行证声明。这包括空字符串或“?” 取决于请求中的存在查询字符串。
添加$args
或添加$query_string
到您的代理通行证声明。这会将查询字符串附加到您的代理请求中。
例子
代替:
proxy_pass http://127.0.0.1:3000$uri;
做:
proxy_pass http://127.0.0.1:3000$uri$is_args$args;
参考
Nginx http 核心模块(导航到嵌入式变量): http: //nginx.org/en/docs/http/ngx_http_core_module.html
推荐阅读
- python-3.x - 提高具有多个条件的 Pandas 子集/过滤器的性能
- reactjs - 折线图上没有渲染注释线
- python - 接受整数或整数列表的 Python 函数
- report - 具有汇总值的 BIRT 报告图表
- java - Selenium 在 Java 中找不到元素
- mysql - 在 phpmyadmin 中创建数据集的实时副本
- java - 如何使用 AssertJ 从列表中映射减少值并断言结果
- python - 如何使用 Python C API 表示“inf”(浮点无穷大)?
- batch-file - 如何在批处理文件中调用设置为“C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe”的变量?
- java - 我似乎无法修复这个空指针异常错误,为什么我会得到它?