Need advice with configuring rails app hosted on heroku to run via an nginx proxy

I have a rails application hosted on heroku with a url like My company requires it to be served such that will point to that heroku instance.

The configuration is as follows

In config/application.rb:

config.action_controller.relative_url_root = "/exampleapp"

In config/environements/*.rb

config.assets.prefix = /exampleapp/assets

And for the routes, I have scoped them to an optional parameter like this

Rails.application.routes.draw do
   scope '(:prefix)' do
      # routes

And in application_controller.rb

def default_url_options
    {prefix:  'exampleapp'}

This will make the application available in both prefixed and unprefixed url. For example: /login and /exampleapp/login will both work just fine and any other prefix will as well.

I guess it wouldn’t matter eitherway. But I want to know if this is a correct way to go about this?

Rails Version: 6.1.4 Ruby Version: 2.7.2

Hello there, The above configuration you have posted is mostly correct. However, I can see a minor issue in your sampler code. You can try my sample code with a few revised explanation, It should look like this:

Rails.application.routes.draw do scope ‘(:prefix)’, prefix: ‘exampleapp’ do # Your routes here end end Rest all will remain same as it is correct. If still it does not work you can also refer to Heroku app