Skip to content

Instantly share code, notes, and snippets.

@c80609a
Created April 27, 2025 15:05
Show Gist options
  • Save c80609a/f61a66bf959c555341c333ffb91f4afe to your computer and use it in GitHub Desktop.
Save c80609a/f61a66bf959c555341c333ffb91f4afe to your computer and use it in GitHub Desktop.
answer.md

To address the issue where an unauthorized request to http://127.0.0.1:8080/rb/admin results in a 404 error instead of routing to the desired path, you need to ensure that your Rails application is correctly configured to handle requests with the /rb prefix. Here are some steps you can take:

  1. Ensure Rails is Aware of the Prefix:

    In your application.rb file, you have already set the config.action_controller.relative_url_root to /rb. This is correct, but ensure that this setting is being applied correctly in your environment.

  2. Check Your Routes:

    Make sure that your Rails routes are set up to handle requests with the /rb prefix. You might need to adjust your routes to account for this prefix. For example, you can use a scope in your routes.rb file:

    Rails.application.routes.draw do
      scope '/rb' do
        # Define your routes here
        get 'admin', to: 'admin/dashboard#index', as: :admin_root
      end
    end
  3. Nginx Configuration:

    Since you are using the Nginx configuration without the rewrite rule, ensure that your Rails application is prepared to handle the /rb prefix. The Nginx configuration you provided should look like this:

    location /rb {
       proxy_pass http://ruby:3000;
       
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
    }

    This configuration forwards requests with the /rb prefix to your Rails application. Ensure that your Rails application is correctly interpreting these requests.

  4. Rails Controller:

    Ensure that your Admin::DashboardController is set up to handle the index action. It should look something like this:

    class Admin::DashboardController < ApplicationController
      def index
        # Your code here
      end
    end
  5. Testing:

    After making these changes, restart your Rails server and Nginx to apply the new configurations. Test the URL http://127.0.0.1:8080/rb/admin to ensure it routes correctly to the admin/dashboard#index action.

By following these steps, you should be able to resolve the 404 error and have your application route requests correctly. If you continue to experience issues, double-check your environment variables and ensure that all services are running as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment