简体   繁体   English

Rails i18n如果我使用unicorn和nginx作为应用程序服务器不起作用

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


When I run my app using default WEBrick server, and set locale from subdomain, i18n works perfectly to "en" and "ja". 当我使用默认的WEBrick服务器运行我的应用程序,并从子域设置区域设置时,i18n完美地适用于“ en”和“ ja”。
However, when I use Nginx and Unicorn to run my app, i18n doesnt work like it does in WEBrick. 但是,当我使用Nginx和Unicorn运行我的应用程序时,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. 除了我将应用程序名称或proxy_pass更改为nginx.conf中的应用程序外,我对unicorn和nginx的设置几乎是默认设置。
Could anyone please teach me how to make i18n work?I'm stack all day.... 有人可以教我如何使i18n正常工作吗?
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: 尝试将以下行添加到您的Nginx配置中location @app-name { }proxy_pass配置之上:

proxy_set_header Host $http_host;

Rails will be sent the proxy_pass setting as the host if this missing from your Nginx config. 如果您的Nginx配置中缺少Rails,它将作为主机发送给proxy_pass设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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