连接到上游时Nginx(111:连接被拒绝)

时间:2015-06-04 15:37:22

标签: ruby-on-rails ubuntu nginx unicorn

我尝试在生产(vps)上运行我的rails应用程序。

我使用rbenv,unicorn,nginx,os ubuntu服务器..

我有配置独角兽和nginx:

file: config / unicorn.rb

app_dir = "/home/axx/apps/axx"

working_directory "/home/axx/apps/axx"
pid "/home/axx/apps/axx/tmp/pids/unicorn.pid"
stderr_path "/home/axx/apps/axx/unicorn/unicorn.log"
stdout_path "/home/axx/apps/axx/unicorn/unicorn.log"

listen "/home/axx/apps/axx/tmp/sockets/unicorn.axx.sock"
worker_processes 2
timeout 30

file: / etc / nginx / sites-available / default

upstream app_server {
  server unix:/home/axx/apps/axx/tmp/sockets/unicorn.axx.sock fail_timeout=0;
}

server {
  listen 80;
  server_name localhost;

  root home/axx/apps/axx/public;

  location / {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    if (-f $request_filename/index.html) {
      rewrite (.*) $1/index.html break;
    }

    if (-f $request_filename.html) {
      rewrite (.*) $1.html break;
    }

    if (!-f $request_filename) {
      proxy_pass http://app_server;
      break;
    }
  }
}

但是当我访问我的网站时,我收到502错误。我也去检查独角兽和nginx:

nginx / error.log

connect() to unix:/home/axx/apps/axx/tmp/sockets/unicorn.axx.sock failed (111: Connection refused) while connecting to upstream,

我尝试在这个网站上搜索一些问题,也搜索谷歌,但我无法解决我的问题。

2 个答案:

答案 0 :(得分:0)

检查unicorn.sock文件的/etc/nginx/nginx.conf文件和路径。在我的情况下,我错过了当前的文件夹目录名称。

答案 1 :(得分:0)

检查上游块中的<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Kendo UI Snippet</title> <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.3.1028/styles/kendo.common.min.css"/> <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.3.1028/styles/kendo.rtl.min.css"/> <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.3.1028/styles/kendo.silver.min.css"/> <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.3.1028/styles/kendo.mobile.all.min.css"/> <script src="http://code.jquery.com/jquery-1.12.4.min.js"></script> <script src="http://kendo.cdn.telerik.com/2016.3.1028/js/kendo.all.min.js"></script> </head> <body> <div id="grid"></div> <script> $("#grid").kendoGrid({ columns: [ { field: "name" }, { field: "age" } ], dataSource: [ { name: "a1", age: 30 }, { name: "a2", age: 33 }, { name: "a3", age: 30 }, { name: "a4", age: 33 }, { name: "a5", age: 30 }, { name: "a6", age: 33 }, { name: "a7", age: 30 }, { name: "a8", age: 33 } ], selectable: "single, row" }); var grid = $("#grid").data("kendoGrid"); function selectionChanged() { let selected = grid.select(); if (selected[0]) { console.log(document.getElementById("label")); document.getElementById("label").value = grid.dataItem(selected).name; } } function selectFirst() { grid.select("tr:first"); selectionChanged(); } function selectLast() { grid.select("tr:last"); selectionChanged(); } function selectNext() { let selected = grid.select(); if (selected[0]) { let index = (selected[0].rowIndex + 1) % grid.items().length; grid.select("tr:eq(" + index + ")"); } selectionChanged(); } function selectPrev() { let selected = grid.select(); if (selected[0]) { let index = selected[0].rowIndex - 1; grid.select("tr:eq(" + index + ")"); } selectionChanged(); } </script> <button onclick="selectFirst()">First</button> <button onclick="selectLast()">Last</button> <button onclick="selectPrev()">Previous</button> <button onclick="selectNext()">Next</button> <br> Selected: <input type="text" id="label" readonly></input> </body> </html> 路径。您可能缺少正确的路径,因为我缺少当前文件夹名称。