Nginx + Rails,默认网址无效

我应该有我的默认网址设置为

example.com/asd/ --->我的root_path

并且一切正确加载。 但是,每次我点击一个

'<%= link_to'something',something_path%>''

我被引导到

example.com/something --->没有/ asd。

这是我的nginx配置或导轨配置的问题吗? 我应该怎么做才能解决它?

--Extra--如果我输入example.com/asd/something,一切都会正常加载。

/etc/nginx/nginx.conf

用户www-data;

worker_processes auto;

pid /run/nginx.pid;

事件{worker_connections 768; }

http {

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    client_max_body_size 250M;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json >application/javascripttext/xml application/xml application/xml+rss >text/javascript;
    include /etc/nginx/passenger.conf;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*; 

}

/etc/nginx/passenger.conf

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;

passenger_ruby /home/rubyuser/.rvm/gems/ruby-2.3.0/wrappers/ruby;

在/ etc / nginx的/网站可用/默认

服务器{

    listen 80 ;
    listen 443 ssl;
    server_name example.com;
    root /home/user/app/current/public;
    passenger_enabled on;
    passenger_app_env production;  

}

production.rb

Rails.application.configure做

    config.cache_classes = true
    config.eager_load = true
    config.consider_all_requests_local= false
    config.action_controller.perform_caching = true
    config.action_dispatch.rack_cache = true
    config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
    config.assets.js_compressor= :uglifier
    config.assets.css_compressor = :sass
    config.assets.compile = true
    config.assets.precompile =  ['*.js', '*.css', '*.css.erb']
    config.assets.digest = true
    config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
    config.log_level = :debug
    config.relative_url_root = "/asd"
    config.action_controller.asset_host = 'example.com'
    config.i18n.fallbacks = true
    config.active_support.deprecation = :notify
    config.log_formatter = ::Logger::Formatter.new
    config.active_record.dump_schema_after_migration = false
    config.force_ssl = false
    Rails.application.routes.default_url_options[:host] = 'example.com/asd'  

结束


我认为问题出在Rails上,而不是Nginx。 也许你错过了一个没有附加“/ asd”的配置(我用RoR已经很长时间了,所以我不记得了)

快速修复可能是为_URL更改_PATH (例如about_path将更改为about_url )并将其添加到ApplicationsController

def default_url_options
   if Rails.env.production?
     {:host => "www.prettyPage.com/asd"}
   else  
     {}
  end
end

_PATH返回相对路径, _URL返回绝对路径。

例如,对于“www.page.com/prettyPics”的_PATH将是“/ prettyPics”,整个URL将是_url。 这可能有点帮助http://guides.rubyonrails.org/routing.html(第2.3部分)

链接地址: http://www.djcxy.com/p/5565.html

上一篇: Nginx + Rails, Default url not working

下一篇: How to run Sinatra App in Passenger with Nginx?