Rails routes / Assets + Proxy issue

OK, so, I’m stumped - I spent most of yesterday trying to figure this one out:

I have a rails app, which runs as it should if accessed as http://MYDOMAIN:8001/

After speaking to a DH support person, I set up proxying so that that unsightly port is not visible in the url. Now the rails app is visible at http://MYDOMAIN/books

However, two issues:

  1. The rails app continues to, understandably, route links to /[rails app name]/[:id], which means the browser goes looking for http://MYDOMAIN/[rails app name]/[:id] (or in the case of the “about” page, http://MYDOMAIN/about) and predictably does not find what should be there. The content shows up if I manually input http://MYDOMAIN/books/[rails app name]/[:id] (or http://MYDOMAIN/books/about).

This is fine! I just want to know how to get Rails (or Apache???) to understand that if I’m going through the proxy, it should link to /books/[whatever] instead of /[whatever].

I am reluctant to change the routes within the app, since I would prefer it still work as normal if accessed explicitly through http://MYDOMAIN:8001/

  1. Assets! Hoo boy. There are approximately eight trillion different search results for people having trouble routing assets, nearly every one of which insists that the solution is precompiling them.

Buddy, let me tell you: it is not.

As mentioned before http://MYDOMAIN/books shows the appropriate content from my rails app, but with no styling. No matter what I do, I make sure the precompiled .js and .css are in the [app root]/public/assets/ folder, and chowned and chmodded appropriately, but they 404 every time.

So I’ve gone through every suggestion I could find. If you’re thinking “maybe I’ll just google this guy’s problem and post a link to literally the first result”, probably don’t do that, because I promise you I have seen that DH forum thread or that stackoverflow discussion or that blog post, and they either were of no help to me or were too different from my setup to be applicable. So if you have any suggestions that aren’t covered already, I’m listening.

(Also, if this is in the wrong forum, feel free to yell at me)

ETA: Rails is v.4.2.4, server is DH VPS running Apache


I’m posting this in case the information here in combination with the information above rings any bells for anybody:

On a whim, I switched from Apache to nginx in the DH VPS configuration, with no attempt at any other configuration changes on the webserver end or the rails end. I have multiple domains on this VPS, and these were my observations:

  1. domains with static pages operated exactly as before (no surprise here, nothing special going on)

  2. domain that used perl/CGI just downloaded the script instead of executing it (also not really surprising, I figured I would have to rework this to some degree)

  3. domain with rails app - pathing magically worked! mostly! links meant for http://MYDOMAIN:8001/[appname]/[:id] and http://MYDOMAIN:8001/about would be routed to http://MYDOMAIN/books/[appname]/[:id] and http://MYDOMAIN/books/about respectively, but links that directed back to root would be routed to

I would have left this as-is were it not for the perl issue - I’d rather have the perl being served correctly and worry about this rails app on my own terms than the other way around, for the time being. So I’m back to Apache with working perl and half-broken rails.

Again, if this and the above post make any lightbulbs go off, please let me know. Thanks in advance for any help on the matter.