2

私は(試行して)ラックスペースにubuntu 11.04サーバーをセットアップして、nginxとunicornでrails3.2アプリを実行しようとしています。この素晴らしいブログを見つけましたhttp://techbot.me/2010/08/deployment-recipes-deploying-monitoring-and-securing-your-rails-application-to-a-clean-ubuntu-10-04-install-using -nginx-and-unicorn /これは私を大いに助けてくれました。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しました)

これはユーザー権限の問題である可能性がありますが、ファイルは実際には存在せず、どのように作成する必要があるのか​​わかりません。手動で作成するのは、原因を修正するのではなく、症状を修正することになると思うので、作成するのは気が進まない。

サーバー上で作成したユーザーにはsudo権限があり、nginxを起動するにはsudoを使用する必要があることにも注意してください。これが正しいかどうかはわかりませんか?これを修正するために私が何を探すべきかについてのポインタは大歓迎です。完全を期すために、私の構成ファイルは次のようになります/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とユニコーンはどちらも正常に動作しているようです

testapp @ airmob:〜/ mobile / current $ 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
4

2 に答える 2

10

関連する構成ファイル(unicorn.rbおよびnginxのデフォルト)でmobile.socketの名前をmobile.sockに変更しました。すべて問題なく、ソケットファイルを作成する必要はなく、期待どおりに機能します。

これは、アプリサーバーが実行されていない場合にも発生します(私の場合はユニコーン)。Unicornがソケットを作成し、nginxがそれを探します。ソケットがない場合、nginxは大騒ぎします。したがって、これを読んで解決策を探している場合は、アプリサーバー(unicorn)が実行されていることを確認し、さまざまな構成ファイル(unicorn.rbおよびnginx.confファイルにソケットが記載されているものは何でも)

于 2012-02-27T10:05:49.833 に答える
1

にあるソケットを使用するように指定した/tmp/mobile.socketので、はい、解決策は単にそれを作成することです。

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

で同じソケットを参照していると仮定しますunicorn.rb

于 2012-02-25T17:42:01.303 に答える