nginx 및 유니콘 Bad GatewayConnect () to UNIX : /tmp/mobile.socket에 실패했습니다 (111 : 연결 거부)

StackOverflow https://stackoverflow.com/questions/9445545

문제

Nginx와 Unicorn을 사용하여 Rails 3.2 앱을 실행하기 위해 Rackspace에서 Ubuntu 11.04 서버를 설정하려면 (시도)입니다. 나는이 멋진 블로그 http://techbot.me/2010/08/deployment-recipes-deploying-monitoring-and-securing-your-rails-application-to -A-Clean-Ubuntu-10-04-install-using-nginx-and-nginx-and-nginx-and-nightorn / in nginx-and-nicon / mysql 설정 문제와 별개로 나쁜 게이트웨이 오류를 제외하고 모든 것을 못 박은 모든 것이 있다고 생각합니다

nginx 오류 로그는 를 표시합니다.

2012/02/25 14:38:34 [crit] 29139#0: *1 connect() to unix:/tmp/mobile.socket failed (2: No such file or directory) while connecting to upstream, client: xx.xx.xxx.xx, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/mobile.socket:/", host: xx.xx.xxx.xx
.

(나는 도메인 X'd 밖으로)

이것은 사용자 권한이 될 수 있지만 파일이 실제로 존재하지 않고 어떻게 작성 해야하는지 모르겠습니다. 나는 원인을 고치는 것이 아니라 증상을 고치는 것보다는 증상을 고정시키는 것처럼 느끼는 것처럼 그것을 수동으로 창조하는 것을 꺼려합니다.

서버에서 생성 한 사용자는 sudo 권한이 있으며 sudo를 사용하여 nginx를 시작해야하며, 확실하지 않은 경우 확실하지 않아야합니다. 내가 이것을 고치기 위해 내가 무엇을 찾아야하는지에 대한 어떤 포인터가 크게 감사드립니다. 완전성을 위해 내 구성 파일은 다음과 같습니다 /etc/init.dunicorn

#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/unicorn_rails
DAEMON_OPTS="-c /home/testapp/mobile/current/unicorn.rb -E production -D"
NAME=unicorn_rails
DESC=unicorn_rails
PID=/home/testapp/mobile/shared/pids/unicorn.pid

case "$1" in
  start)
echo -n "Starting $DESC: "
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
  stop)
echo -n "Stopping $DESC: "
        kill -QUIT `cat $PID`
echo "$NAME."
;;
  restart)
echo -n "Restarting $DESC: "
        kill -QUIT `cat $PID`
sleep 1
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
.

및 / etc / nginx / sites-available / default 의 nginx 구성

# as we are going to use Unicorn as the application server
# we are not going to use common sockets
# but Unix sockets for faster communication
upstream mobile {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  # for UNIX domain socket setups:
  server unix:/tmp/mobile.socket fail_timeout=0;
}

server {
    # if you're running multiple servers, instead of "default" you should
    # put your main domain name here
    listen 80 default;
# you could put a list of other domain names this application answers
server_name localhost;

root /home/testapp/mobile/current/public;
access_log /var/log/nginx/mobile_access.log;
rewrite_log on;

location / {
    #all requests are sent to the UNIX socket
    proxy_pass http://mobile;
    proxy_redirect off;

    proxy_set_header Host $host:$proxy_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    client_max_body_size 10m;
    client_body_buffer_size 128k;

    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;

    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;
}

# if the request is for a static resource, nginx should serve it directly
# and add a far future expires header to it, making the browser
# cache the resource and navigate faster over the website
location ~ ^/(images|javascripts|stylesheets|system)/ {
  root /home/testapp/mobile/current/public;
  expires max;
  break;
}

}
.

업데이트 내 Unicorn.rb 파일

# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
worker_processes 4
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/home/testapp/mobile/current"
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/tmp/mobile.socket", :backlog => 64
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
# feel free to point this anywhere accessible on the filesystem
user 'testapp', 'testapp'
shared_path = '/home/testapp/mobile/shared'
pid "#{shared_path}/pids/unicorn.pid"
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"
.

제안에 따라 Mobile.socket 파일을 수동으로 만들었으며 이제 다음 오류가 발생합니다

[error] 1083#0: *4 connect() to unix:/tmp/mobile.socket failed (111: Connection refused) while connecting to upstream
.

은 Mobile.socket 파일에 대한 사용 권한 만 있습니까? 그렇다면 어떤 권한이 필요합니까?

업데이트 2 Nginx와 Unicorn은 모두 을 실행하는 것 같습니다.

testApp @ airmob : ~ / 모바일 / 현재 $ PS Aux | grep nginx

root      6761  0.0  0.1  71152  1224 ?        Ss   18:36   0:00 nginx: master process /usr/sbin/nginx
testapp   6762  0.0  0.1  71492  1604 ?        S    18:36   0:00 nginx: worker process
testapp   6763  0.0  0.1  71492  1604 ?        S    18:36   0:00 nginx: worker process
testapp   6764  0.0  0.1  71492  1604 ?        S    18:36   0:00 nginx: worker process
testapp   6765  0.0  0.1  71492  1604 ?        S    18:36   0:00 nginx: worker process
testapp  13071  0.0  0.0   8036   600 pts/0    R+   21:21   0:00 grep --color=auto nginx
.

도움이 되었습니까?

해결책

관련 구성 파일 (Unicorn.rb 및 nginx 기본값)의 Mobile.sock으로 Mobile.sock으로 이름을 변경했으며 모든 것이 좋습니다. 소켓 파일을 만들 필요가 없으며 예상대로 작동합니다.

앱 서버가 실행되고 있지 않으면 (내 경우 유니콘에서)도 발생합니다.유니콘은 소켓을 만듭니다. Nginx는 그것을 찾습니다.소켓이 없으면 Nginx는 소란을 걷어 찼습니다. 따라서 솔루션을 읽는이 해결책을 읽는 경우 앱 서버 (유니콘)가 실행 중이고 다양한 구성 파일 (Unicorn.rb 및Nginx.conf 파일에 소켓이 언급되어 있지 않음)

다른 팁

/tmp/mobile.socket에있는 소켓을 사용해야합니다. 그래서 예, 솔루션은 단순히 생성하는 것입니다.

upstream mobile {
  # for UNIX domain socket setups:
  server unix:/tmp/mobile.socket fail_timeout=0;
}
.

unicorn.rb에서 동일한 소켓을 참조하고 있다고 가정합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top