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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With