Search code examples
ruby-on-railsinternationalizationnginxunicorn

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".
However, when I use Nginx and Unicorn to run my app, i18n doesnt work like it does in 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.


Solution

  • 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.