2015-09-05 4 views
1

J'ai mis nginx et licorne sur ubuntu14.04 pour accéder à mon application rails!nginx et licorne ne fonctionne pas

mais j'accéder à mon domaine, chrome responsed « connexion refusée »

Je ne sais pas pourquoi ...

Comment puis-je résoudre ce problème?

Il y a mon fichier nginx.conf et unicorn.

【】 nginx.conf

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 

    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 
    # server_tokens off; 

    # server_names_hash_bucket_size 64; 
    # server_name_in_redirect off; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    ## 
    # Logging Settings 
    ## 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    ## 
    # Gzip Settings 
    ## 

    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/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # nginx-naxsi config 
    ## 
    # Uncomment it if you installed nginx-naxsi 
    ## 

    #include /etc/nginx/naxsi_core.rules; 

    ## 
    # nginx-passenger config 
    ## 
    # Uncomment it if you installed nginx-passenger 
    ## 

    #passenger_root /usr; 
    #passenger_ruby /usr/bin/ruby; 

    ## 
    # Virtual Host Configs 
    ## 

    #include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

【monapp-unicorn】 (/ etc/nginx// myapp-unicorn compatible place)

upstream myapp.com { 
    #my rails app 
    server unix:/var/www/rails/myapp/tmp/sockets/unicorn.sock  fail_timeout=0; 
} 

server { 
    listen 80; 
    server_name myapp.com; 
    location/{ 
     proxy_redirect off; 
     proxy_set_header Host    $host; 
     proxy_set_header X-Real-IP   $remote_addr; 
     proxy_set_header X-Forwarded-Host $host; 
     proxy_set_header X-Forwarded-Server $host; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     client_max_body_size 35M; 
     proxy_pass http://myapp.com; 
    } 
} 

【】 unicorn.rb (/ var /www/rails/myapp/config/unicorn.rb)

worker_processes 2 

listen File.expand_path('tmp/sockets/unicorn.sock', ENV['RAILS_ROOT']) 

stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) 
stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT']) 

preload_app true 

before_fork do |server, worker| 
    defined?(ActiveRecord::Base) and  ActiveRecord::Base.connection.disconnect! 
    old_pid = "#{ server.config[:pid] }.oldbin" 

    unless old_pid == server.pid 
     begin 
      Process.kill :QUIT, File.read(old_pid).to_i 
     rescue Errno::ENOENT, Errno::ESRCH 

     end 
    end 
end 

after_fork do |server, worker| 
    defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 
end 

Nous vous remercions de votre patience avec mon pauvre anglais.

Ajouter

c'est unicorn.log (/var/www/rails/myapp/log/unicorn.log)

I, [2015-09-05T18:17:20.590239 #10832] INFO -- : Refreshing Gem list 
I, [2015-09-05T18:17:22.099133 #10832] INFO -- : unlinking existing socket=/var/www/rails/myapp/tmp/sockets/unicorn.sock 
I, [2015-09-05T18:17:22.099389 #10832] INFO -- : listening on addr=/var/www/rails/myapp/tmp/sockets/unicorn.sock fd=11 
I, [2015-09-05T18:17:22.115503 #10832] INFO -- : master process ready 
I, [2015-09-05T18:17:22.118878 #10836] INFO -- : worker=0 ready 
I, [2015-09-05T18:17:22.127008 #10839] INFO -- : worker=1 ready 

c'est nginx.log (/ var/log/nginx/error.log)

Le journal nginx est pas ...

+0

Partager erreur Unicorn et Nginx enregistre tous les deux – Anatoly

+0

vous remercie pour votre réponse! J'ai ajouté des journaux! –

+0

Le journal des erreurs Nginx ne doit pas être vide, recherchez les détails. Cela ressemble à: * connexion() échouée (111: Connexion refusée) lors de la connexion en amont, client .... * besoin de plus de détails du journal Nginx. Essayez de renommer en amont, ne le faites pas ressembler à FQDN. – Anatoly

Répondre

0

Si votre erreur est

connect() failed (111: Connection refused) while connecting to upstream 

Essayez de lancer licorne écouter sur

listen /tmp/sockets/unicorn.sock 

au lieu de

listen File.expand_path('tmp/sockets/unicorn.sock', ENV['RAILS_ROOT']) 

parce que quelques fois il arrive que nginx ne peut pas lire ce fichier socket en raison d'autorisations. Il est plutôt sûr si vous avez un fichier socket à l'intérieur du dossier tmp. signaler également que vous NGINX à

server unix:/tmp/sockets/unicorn.sock  fail_timeout=0; 

au lieu de

server unix:/var/www/rails/myapp/tmp/sockets/unicorn.sock  fail_timeout=0; 

S'il vous plaît répondre si vous obtenez toujours une erreur
Bonne déploiement;)

+0

C'est une réponse incorrecte! Unicorn master a été démarré avec succès. – Anatoly

+0

@Anatoly bien que licorne et nginx a démarré avec succès la plupart du temps la connexion refusée vient quand nginx n'a pas finit le fichier de chaussette ou n'a pas pu lire ce fichier de chaussette ..... –

+0

comment le savez-vous sans erreur log? – Anatoly