Answer the question
In order to leave comments, you need to log in
Rails4 how to set relative_url_root other than '/'?
Greetings Toasters. Mind on fire. Help put out the fire
Solving the problem of simplifying the deployment of Rails applications in a demo environment, I ran into a couple of problems.
Plot:
I wanted the deployment for the demo environment to take place, with minimal participation of hands.
Namely, put all demo applications, for demonstration, into folders /var/www/apps/demo/$sitename/current/public
and so that nginx resolves $sitename based on the demo.server.ru/sitename address.
This has been successfully implemented here .
But a new problem looms, Rails says:
ActionController::RoutingError (No route matches [GET] "/sitename"):
// config/enviroments/production.rb
config.relative_url_root = "/sitename"
config.action_controller.relative_url_root = "/sitename"
map '/sitename' do
run Myapp::Application
end
Answer the question
In order to leave comments, you need to log in
In general, the story ended with success.
It turned out that the problem in routing was with static pages because of the High_Voltage gem.
You can get around this problem like this.
# config/initializers/high_voltage.rb
HighVoltage.configure do |config|
config.routes = false
end
# config/routes.rb
Rails.application.routes.draw do
scope '/appname' do
#переопределяем дефолтный путь high_voltage на свой Page контроллер
get "/pages/*id" => 'pages#show', as: :page, format: false
resources :events
root 'home_page#index'
end
end
server {
listen 80;
client_max_body_size 4G;
keepalive_timeout 10;
error_page 500 502 504 /500.html;
error_page 503 @503;
server_name demo.server.ru;
root /var/www/apps/demo/app_name/current/public;
location /app_name{
try_files $uri @app_name_production;
}
location @app_name_production {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unicorn_app_name_production;
access_log /var/log/nginx/app_name_production.access.log;
error_log /var/log/nginx/app_name_production.error.log;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location = /50x.html {
root html;
}
location = /404.html {
root html;
}
location @503 {
error_page 405 = /system/maintenance.html;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
rewrite ^(.*)$ /503.html break;
}
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question