3

I created a rails app that is deployed into a subdirectory of my Vultr server. Somehow, no GET parameters are considered by the backend. For example, calls from the ForestAdmin API don't read GET parameters (see issue here). Also, my search page is not receiving GET parameters, example for this search query in production, I get the following logs:

logs

As you can see, in the title, the « » is blank as it should display the q parameter.

My Rails app config seems right, so I guess it's a server configuration issue.

Here are my routes:

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

And here is my nginx config:

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;
}

and

location /dictionnaire {
    try_files $uri $uri/ /dictionnaire/index.php?q=$uri&$args;
}

Any idea what could be the issue preventing the parameters from being passed?

pygeek
  • 7,356
  • 1
  • 20
  • 41
nico_lrx
  • 715
  • 1
  • 19
  • 36
  • how are you running the rails server, using puma or unicorn or any other? – Kasi Raj R Oct 14 '20 at 04:44
  • What to rails logs show? If you do `tail -f log/development.log | grep -A 5 'Started'`, do the log statements there include the params? If not, what do the nginx logs show? `sudo tail -f var/log/nginx/access.log | grep ... ` – Navid Khan Oct 16 '20 at 08:27
  • Please add example request. – pygeek Oct 17 '20 at 07:01
  • The rails server is using Puma. I added an example request with the logs in the question. @NavedKhan there is no access.log into the nginx directory, but nginx error logs for the website doesn't show any error. Thanks! – nico_lrx Oct 17 '20 at 10:19

1 Answers1

3

Problem

proxy_pass is not forwarding query strings to rails application

Solution

Add $is_args to your proxy pass statement. This includes either empty string or “?” depending on presence query string in request.

Add $args or $query_string to your proxy pass statement. This appends the query string to your proxied request.

Example

Instead of:

proxy_pass http://127.0.0.1:3000$uri;

Do:

proxy_pass http://127.0.0.1:3000$uri$is_args$args;

References

Nginx http core module (navigate to embedded variables): http://nginx.org/en/docs/http/ngx_http_core_module.html

https://stackoverflow.com/a/8130872/806876

pygeek
  • 7,356
  • 1
  • 20
  • 41