title: How to really set up a Rails 4.2 application in a subdirectory? Using nginx and puma
body: <p>First I have to say that I tried it hard for a long time.
  I have a application that's in /home/deploy/app/myapp and want to deploy it to be accessed in <a href="http://myurl.com/myapp" rel="nofollow">http://myurl.com/myapp</a> because I want to have many others over the same domain name.</p>
  
  <p>The problem is that Rails default configuration is not working like it should. Some say that I should just put a configuration in application.rb or in production.rb or a environment variable (RAILS_RELATIVE_URL_ROOT) [ <a href="http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root" rel="nofollow">http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root</a> ]. But I keep getting 404. The only way that it worked was when I put this in the routes.rb:</p>
  
  <pre><code>Rails.application.routes.draw do
   scope '/myapp' || '/' do
    root 'home#index'
   end
  end
  </code></pre>
  
  <p>It fells wrong. The "config.relative_url_root" should work. Don't it?</p>
  
  <p>And another thing is that the assets is still wrong. I can't get them right. What should I do?</p>
  
  <p>My NGINX config is:</p>
  
  <pre><code>upstream myapp {
    server unix:///home/deploy/apps/myapp/shared/tmp/sockets/puma.sock;
  }
  
  server {
    listen 80;
    server_name myapp;
    keepalive_timeout 5;
    access_log /home/deploy/apps/myapp/current/log/production.access.log;
    error_log /home/deploy/apps/myapp/current/log/production.error.log info;
  
    if (-f $document_root/maintenance.html) {
      rewrite  ^(.*)$  /maintenance.html last;
      break;
    }
  
    location @myapp {
      proxy_pass http://myapp;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
  
    location /myapp {
      alias /home/deploy/apps/myapp/current/public;
      try_files $uri @myapp;
    }
  }
  </code></pre>
  
  <p>How can I fix the assets in a way that NGINX server it also?</p>
  
  <p>Thank you!</p>