我创建了一个Rails应用程序,该应用程序已部署到Vultr服务器的子目录中。不知何故,后端不考虑GET参数。例如,来自ForestAdmin API的调用不会读取GET参数(see issue here)。另外,我的搜索页面没有收到GET参数,例如生产中的this search query示例,我得到以下日志:
如您所见,标题中的«»为空白,因为它应显示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;
}
您知道阻止参数传递的问题是什么吗?
答案 0 :(得分:2)
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