Answer the question
In order to leave comments, you need to log in
How to solve the problem with routing in rails when proxying nginx?
Given:
HOST1 address: free.magazine.ru/1c/ , which is proxied via nginx (config below) to HOST2
1c.partner.ru, where the Rails application is deployed ( ruby 2.1.0, rails 4.1.4, unicorn + nginx ).
HOST1 NGINX CONF
location ^~ /1c {
proxy_pass http://1c.partner.ru;
include includes/upstream_proxyhost.conf;
proxy_redirect http://1c.partner.ru/ /;
}
upstream 1c-new {
server unix:/tmp/unicorn.1c-new.sock fail_timeout=0;
}
server {
listen 80;
server_name 1c.partner.ru;
root /home/deployer/1c/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @1c-new;
location @1c-new {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://1c-new;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
1c::Application.routes.draw do
#scope "/1c/" do
resource :session
resources :users
resources :oauth
resources :categories do
member do
get :online, :home
end
end
resources :products do
member do
get :online, :home, :go
end
end
match 'logout', to: 'sessions#destroy', via: :get
match 'search', to: 'welcome#search', via: :get
match 'regulation', to: 'welcome#regulation', via: :get
match 'online', to: 'welcome#online', via: :get
match 'home', to: 'welcome#home', via: :get
#
root to: 'welcome#online'
#end
end
#1c::Application.routes.default_url_options[:host] = 'free.magazine.ru'
server {
listen 80;
server_name free.magazine.ru;
location ^~ /1c {
proxy_pass http://1c.partner.ru;
}
}
server {
listen 80;
server_name 1c.roscontent.ru;
root /home/deployer/1c/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @h5c-new;
location @1c-new {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://1c-new;
}
}
1c::Application.routes.draw do
scope "/1c/" do
resource :session
resources :users
resources :oauth
resources :categories do
member do
get :online, :home
end
end
resources :products do
member do
get :online, :home, :go
end
end
match 'logout', to: 'sessions#destroy', via: :get
match 'search', to: 'welcome#search', via: :get
match 'regulation', to: 'welcome#regulation', via: :get
match 'online', to: 'welcome#online', via: :get
match 'home', to: 'welcome#home', via: :get
#
root to: 'welcome#online'
end
end
module 1c
class Application < Rails::Application
config.relative_url_root = '/1c'
end
end
config.assets.prefix = File.join((config.relative_url_root || '/'), 'assets')
Answer the question
In order to leave comments, you need to log in
Are you talking about it?
The default location for the manifest is the root of the location specified in config.assets.prefix ('/assets' by default).
(this is about assets)
UPD found this solution regarding links
https://community.webfaction.com/questions/9563/wr...
UPD2 and this
ENV["RAILS_RELATIVE_URL_ROOT"] is used by the routing code to recognize URLs when you deploy your application to a subdirectory.
guides.rubyonrails.org/configuring.html#deploy-to-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question