サーバー初心者のものですが設定に苦戦しております。
さくらvpsのubuntu、nginx、unicorn、sinatraを動かそうとしております。
どの付近を修正すればいいのかご教授いただけますでしょうか。
ブラウザ上で下記を実行するとエラーになっております。
http://hogehoge.com:8000/
2016/05/15 00:46:14 [error] 10607#0: *4 connect() to unix:/usr/share/nginx/html/hogehoge/tmp/sockets/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 999.999.999.999, server: hogehoge.com, request: "GET / HTTP/1.1", upstream: "http://unix:/usr/share/nginx/html/hogehoge/tmp/sockets/unicorn.sock:/", host: "hogehoge.com:8000"
■フォルダ構成
app.rb
config - unicorn.rb
config.ru
Gemfile
log
public - index.html
tmp - pid - unicorn.pid
tmp - sockets - unicorn.sock
■app.rb ★ここのページを表示したい。
require 'sinatra/base'
class App < Sinatra::Base
get '/' do
"<p>This is <i>dynamic</i> content served via unicorn: #{rand(36**6).to_s(36)}"
end
end
■unicornの設定
unicorn -c /usr/share/nginx/html/hogehoge/config/unicorn.rb -E production -D
を実行
ps -ef --forest | grep unicorn
で確認
user 10702 7657 0 00:51 pts/0 00:00:00 _ grep --color=auto unicorn
user 10676 1 0 00:45 ? 00:00:00 unicorn master -c /usr/share/nginx/html/hogehoge/config/unicorn.rb -E production -D
user 10679 10676 0 00:45 ? 00:00:00 _ unicorn worker[0] -c /usr/share/nginx/html/hogehoge/config/unicorn.rb -E production -D
user 10682 10676 0 00:45 ? 00:00:00 _ unicorn worker[1] -c /usr/share/nginx/html/hogehoge/config/unicorn.rb -E production -D
unicorn.rb内容
@dir = "/home/[ユーザー名]/projects/hogehoge/"
worker_processes 2
working_directory @dir
timeout 30
listen "#{@dir}tmp/sockets/unicorn.sock", :backlog => 64
pid "#{@dir}tmp/pids/unicorn.pid"
stderr_path "#{@dir}log/unicorn.stderr.log"
stdout_path "#{@dir}log/unicorn.stdout.log"
■nginxの設定
/etc/nginx/sites-available/default
server {
listen 8000 default_server;
listen [::]:8000 default_server ipv6only=on;
server_name hogehoge.com;
location / {
root /usr/share/nginx/html/hogehoge/public/;
index index.html index.htm;
}
}
/etc/nginx/nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
sendfile on;
tcp_nopush on;
keepalive_timeout 5;
tcp_nodelay on;
gzip on;
gzip_vary on;
gzip_min_length 500;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml image/x-icon;
upstream unicorn_server {
server unix:/usr/share/nginx/html/hogehoge/tmp/sockets/unicorn.sock
fail_timeout=0;
}
server {
server_name hogehoge.com;
root /usr/share/nginx/html/hogehoge/public/;
listen 8000;
client_max_body_size 4G;
keepalive_timeout 5;
location / { try_files $uri @app; } location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; # pass to the upstream unicorn server mentioned above proxy_pass http://unicorn_server; }
}
}
回答2件
あなたの回答
tips
プレビュー