V
V
Vayladion Gognazdiak2016-03-21 12:07:07
Ruby on Rails
Vayladion Gognazdiak, 2016-03-21 12:07:07

Why crookedly fulfills the redirect rails?

Good day.
There is a site on rails ( ruby ​​2.2.2, rails 4.1.4 )
Unicorn + nginx is used for work.
At some point, you need to redirect to a folder that is in the basket on Amazon.
The folder contains the usual html5 game (index.html + js folder with the corresponding scripts).
The redirect is done as standard,
redirect_to @game.html_url
@game.html_url -> name.myname.ru/uploads/html_file/product-1364/supe...
In the log:

Redirected to http://name.myname.ru/uploads/html_file/product-1364/supergame/gamefiles/index.html
Completed 302 Found in 1662ms (ActiveRecord: 0.0ms)
Started GET "/products/1364/js/pn.js" for xxxx at 2016-03-21 11:38:39 +0300
Started GET "/products/1364/js/phaser.min.js" for xxxxx at 2016-03-21 11:38:39 +0300
Started GET "/products/1364/assets/img/rotate_screen.png" for xxxxx at 2016-03-21 11:38:39 +0300

ActionController::RoutingError (No route matches [GET] "/products/1364/js/pn.js"
ActionController::RoutingError (No route matches [GET] "/products/1364/assets/img/rotate_screen.png")
ActionController::RoutingError (No route matches [GET] "/products/1364/js/phaser.min.js"

Those. the search for js scripts for some reason goes the wrong way.
How to force to take resources on a correct way?
PS: If you add a second server_name with a domain different from the first one to the nginx config and change the domain to @game.html_url via gsub, then everything works fine.
nginx config:
upstream my-site {
  server unix:/tmp/unicorn.my-site.sock fail_timeout=0;
}
server {
  listen 80;
  server_name name.myname.ru;

  root /home/putin/my-site/current/public;

  location /uploads/ {
    proxy_pass http://bucket.s3.amazonaws.com;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @my-site;

  location @my-site{
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://my-site;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question