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:
-
Ensure Rails is Aware of the Prefix:
In your
application.rb
file, you have already set theconfig.action_controller.relative_url_root
to/rb
. This is correct, but ensure that this setting is being applied correctly in your environment. -
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 yourroutes.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
-
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. -
Rails Controller:
Ensure that your
Admin::DashboardController
is set up to handle theindex
action. It should look something like this:class Admin::DashboardController < ApplicationController def index # Your code here end end
-
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 theadmin/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.