Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Rails+Passenger+Devise from a subdirectory?

I have a server A which proxies all traffic on /rails to server B.

So I setup this virtual host, and most things work...okay. link_to is broken and generates urls to /users as opposed to /rails/users, but I can work around that.

If I set config.action_controller.relative_url_root to /rails then my routes work okay EXCEPT all the devise routes. They point to the bare URL. How do I properly configure server B to understand that its running in a subdirectory and generate links and routes correctly?

<VirtualHost *:80>
    ServerName http://ec2-url.compute-1.amazonaws.com/
    SetEnv RDS_HOSTNAME "mydb..."
    SetEnv RAILS_RELATIVE_URL_ROOT "/rails"

    DocumentRoot /home/ubuntu/myapp/public
    RailsEnv staging 
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/app.log combined
    PassengerLogLevel 3
    <Directory "/home/ubuntu/myapp/public">
 Options FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
   Options -MultiViews
   Require all granted
    </Directory>
</VirtualHost>

I am using Rails 4.

like image 378
Stefan Kendall Avatar asked Apr 10 '15 19:04

Stefan Kendall


1 Answers

In your environment files, add a config for OmniAuth.config.full_host.

OmniAuth.config.full_host = 'http://myfullurl/subdir'

Now, in application_controller.rb, add this method:

def after_sign_in_path_for(resource_or_scope)
    path = super(resource_or_scope)
    "#{OmniAuth.config.full_host}#{path}"
end
like image 50
Stefan Kendall Avatar answered Sep 21 '22 13:09

Stefan Kendall