I’d like routes like /wiki and /forum to pass traffic through to another website (on another host), so it looks to users like they’re on the same domain. I also have a number of redirects, e.g. /xyz redirects to a separate domain to maintain old links.

I currently implement these all in nginx, and “everything else” is proxied to my rails app.

In the DO app platform world, I assume I should use the rails router for redirects, but what about proxying? Should I use rack proxy or something? Or is there some way to control routing at a higher layer in the app platform (e.g. via some ingress container)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You can control the routes for components within your app on the “Components” tab the “HTTP Routes” section. We don’t currently offer the ability to configure arbitrary redirects, though it is functionality we are considering. You should be able to make these redirects easily within the rails routing layer.

As far as reverse proxying, it’s unlikely we’ll add functionality for proxying outside the App Platform directly. I’m not familiar with the Rack::Proxy, but it looks like it could work. You could also run nginx as a service within your application using a Dockerfile. We have an example nginx Dockerfile and configuration available in our sample repos at https://github.com/digitalocean/sample-nginx. To avoid unnecessary load, I recommend keeping your existing routes for the rails application, and add new routes to nginx just for the parts you want to proxy.

  • @cbaker wouldn’t that require I put my entire (rails) app into a Docker image that I manage, and add nginx within it? My concerns with this are (a) I would lose the benefit of your standard, production-hardened buildpack and end up running my medicore Dockerfile in production, and (b) I’d have to run multiple processes in the docker container (assumedly via a supervisor). Unless I’m misunderstanding?

    • @cbaker Okay I think I understand what you meant. I’ve created a separate nginx container that is simply a list of redirects/proxy rules. I’ve added it as a component to my app, then added HTTP routes to it to route traffic to it for certain paths. For instance, /wiki is routed to my nginx container. My nginx container has a location /wiki { return 301 ... } rule in it.

      The problem is, I actually have to go to /wiki/wiki to trigger it! I can understand what’s going on here: DO itself is reverse proxying the requests, so when I go to /wiki/, my nginx container just receives a request for /.

      The logical fix would be to set the http route to /, but that’s where my rails app is running.

      Any suggestions?