Background
For my work, we have two different networks, the developers network, and the general company network. I need to expose the rails app to both, running under a sub uri so that the people on the general network can get to the app from foo.bar.com/{app_name}, and on the developer network from http://{server_name}.{dev_network}.dev/{app_name}. Sadly, we are not allowed to use Passenger, as this is an enterprise application.
Currently, I have the app running on a sub uri, and able to be accessed from both networks, but I am running into errors. I will list the errors I am seeing, then the nginx config I have created, as well as the rails_app config to work with the sub uri.
Problems
Configurations
Nginx VHost in sites-available, symlinked to sites-enabled.
upstream claxon {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name claxon;
root /var/www;
location ~* ^/claxon/ {
alias /var/www/claxon/public;
proxy_pass http://claxon;
}
location ^~ /assets/ {
root /var/www/claxon/public/claxon;
}
location ^~ /original_user_images/ {
root /var/www/claxon/public/claxon;
}
}
Rails App
config/initializers/mount_location.rb
if Rails.env.production?
Rails.application.config.relative_url_root = '/claxon'
end
config.ru
map Rails.application.config.relative_url_root || '/' do
run Rails.application
end
config/environments/production.rb
# Configures assets to be compiled under public/claxon/assets
config.assets.prefix = 'claxon/assets'
Additional Details
The answer to this question was to ultimately configure the rails app to server the assets from a 'asset_host'. I set the asset host url to be the same as if connecting to the server from the enterprise network, as the developer network is contained within it, but the enterprise network cannot see the development network. Configuring it this way allows for both networks to receive the assets, and work across a refresh.
This final configuration in the production.rb file is as such.
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = "https://foo.bar.com/claxon/"
This allows all assets to be derived from https://foo.bar.com/claxon/claxon/assets/....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.