Getting an error `127.0.0.1' is not a valid domain after every request on my rails app running on nginx server with unicorn. What to check?

July 18, 2019 158 views
Nginx Ubuntu 16.04

****## Server Configuration

upstream app {
server unix:/home/deploy/project/shared/sockets/unicorn.sock fail_timeout=0;
}

server {
listen 80;
server_name *.mydomain;

root /home/deploy/project/current/public;

try_files $uri/index.html $uri @app;

location @app {
    proxy_pass http://app;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;

}

****## Stack trace

…by-2.1.2/gems/publicsuffix-1.5.1/lib/
public
suffix.rb: 62:in parse'
…ploy/bookafy/app/controllers/
application_controller.rb: 72:in
setdomainvariable'
…ser-timezone-rails-1.0.1/lib/
browser-timezone-rails.rb: 15:in set_time_zone'
…1.2/gems/actionview-4.1.5/lib/action_view/
rendering.rb: 30:in
process'
…ct-1.3.1/app/middleware/
recurringselectmiddleware.rb: 24:in call'
…ems/apipie-rails-0.3.6/lib/apipie/
static_dispatcher.rb: 65:in
call'
…gems/ruby-2.1.2/gems/turnout-2.4.1/lib/rack/
turnout.rb: 25:in call'
…uby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
strategy.rb: 186:in
call!'
…uby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
strategy.rb: 164:in call'
…uby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
strategy.rb: 186:in
call!'
…uby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
strategy.rb: 164:in call'
…uby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
strategy.rb: 186:in
call!'
…uby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
strategy.rb: 164:in call'
…ruby-2.1.2/gems/omniauth-1.2.2/lib/omniauth/
builder.rb: 59:in
call'
…ms/apipie-rails-0.3.6/lib/apipie/extractor/
recorder.rb: 132:in call'
…m/gems/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
deflater.rb: 25:in
call'
…ems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/
manager.rb: 35:in block in call'
…ems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/
manager.rb: 34:in
catch'
…ems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/
manager.rb: 34:in call'
…/.rvm/gems/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
etag.rb: 23:in
call'
…/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
conditionalget.rb: 25:in call'
…/.rvm/gems/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
head.rb: 11:in
call'
…-2.1.2/gems/rack-1.5.5/lib/rack/session/abstract/
id.rb: 225:in context'
…-2.1.2/gems/rack-1.5.5/lib/rack/session/abstract/
id.rb: 220:in
call'
…ruby-2.1.2/gems/quietassets-1.1.0/lib/
quiet
assets.rb: 27:in call_with_quiet_assets'
…ms/request_store-1.2.0/lib/request_store/
middleware.rb: 8:in
call'
…/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
methodoverride.rb: 21:in call'
…vm/gems/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
runtime.rb: 17:in
call'
…m/gems/ruby-2.1.2/gems/rack-1.5.5/lib/rack/
sendfile.rb: 112:in call'
…by-2.1.2/gems/unicorn-5.5.0/lib/unicorn/
http_server.rb: 605:in
processclient'
…vm/gems/ruby-2.1.2/gems/spawnling-2.1.6/lib/
patches.rb: 74:in `process
client'
…by-2.1.2/gems/unicorn-5.5.0/lib/unicorn/
httpserver.rb: 700:in `workerloop'
…by-2.1.2/gems/unicorn-5.5.0/lib/unicorn/
httpserver.rb: 548:in `spawnmissingworkers'
…by-2.1.2/gems/unicorn-5.5.0/lib/unicorn/
http
server.rb: 144:in `start'

1 comment
  • Just to get a bit more info, are you getting that error when you are going to domain.com in your browser?

    Or where exactly are you receiving the error message, in browser, terminal, etc.:
    error `127.0.0.1' is not a valid domain

1 Answer

@moisey I am getting the error in the application logs ie. unicorn.stdout.log

  • Can you provide the output of the error log?

    Also what do you have in your /etc/hosts file?

    • @moisey Thanks for helping.

      I get this in this the logs:

      Started GET "/" for 127.0.0.1 at 2019-07-19 20:34:47 +0000
      Processing by HomeController#index as HTML
      "user time zone: "
      Fri, 19 Jul 2019 13:34:47 PDT -07:00
      "127.0.0.1"
      Completed 500 Internal Server Error in 2ms

      PublicSuffix::DomainInvalid (127.0.0.1' is not a valid domain):
      app/controllers/application_controller.rb:72:in
      setdomainvariable'

      The /etc/hosts file has the default settings:
      127.0.0.1 localhost

      The following lines are desirable for IPv6 capable hosts

      ::1 ip6-localhost ip6-loopback
      fe00::0 ip6-localnet
      ff00::0 ip6-mcastprefix
      ff02::1 ip6-allnodes
      ff02::2 ip6-allrouters
      ff02::3 ip6-allhosts
      ~

      ~

      • So the relevant line:

        PublicSuffix::DomainInvalid (127.0.0.1' is not a valid domain):
        app/controllers/application_controller.rb:72:insetdomainvariable'
        

        Which means that on line #72 of your application_controller.rb you have an error.

        Specifically you are calling PublicSuffix::DomainInvalid which is used to check if you have supplied a valid domain suffix like .com, .net, etc, but it looks like you are passing in 127.0.0.1 instead of a domain name, which isn't a valid domain name and as a result it doesn't have a valid DomainSuffix and that's why you are getting that error.

        If you have a configuration file for this app, it probably has 127.0.0.1 listed somewhere and you should replace that with the expected domain. But really it's a code issue not a deployment issue or configuration of your webserver, ruby on rails, etc.

Have another answer? Share your knowledge.