简体   繁体   中英

Rails i18n if I use unicorn and nginx as a application server doesnt work


When I run my app using default server, and set locale from subdomain, i18n works perfectly to "en" and "ja". 服务器运行我的应用程序,并从子域设置区域设置时,i18n完美地适用于“ en”和“ ja”。
However, when I use to run my app, i18n doesnt work like it does in WEBrick. 运行我的应用程序时,i18n无法像在WEBrick中那样工作。

I write below codes to set locale from subdomain;

 def set_locale                                          
    I18n.locale = params[:locale] || I18n.default_locale  
     if request.host.starts_with? "en."                    
      I18n.locale = "en"                                  
     else                                                  
      I18n.locale = "ja"                                  
     end                                                   
 end


What am I missing here?
My settings for unicorn and nginx are almost default except I changed the app name or the proxy_pass to app in nginx.conf.
Could anyone please teach me how to make i18n work?I'm stack all day....
Please excuse my poor English skill...
Thank you in advance.

Try adding the following line to your Nginx config inside your location @app-name { } or above your proxy_pass config:

proxy_set_header Host $http_host;

Rails will be sent the proxy_pass setting as the host if this missing from your Nginx config.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM