こちらの記事を参考にしています。
VPS上にNginx、Unicorn、Sinatraを導入して、ウェブサイトを展開しようとしています。Nginxの起動、Sinatraアプリの起動自体は成功しました。しかしブラウザにて確認すると、「An error occurred. Sorry, the page you are looking for is currently unavailable. Please try again later.」という表記が出て正常に動作しません。これは何が原因であろうと考えられるでしょうか。よろしくお願い申し上げます。他に必要な情報があれば是非おっしゃってください。
/etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { server_tokens off; include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; upstream Sinatra { server unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock; } }
/etc/nginx/conf.d/default.conf
server { listen 80; server_name localhost; #access_log /var/log/nginx/host.access.log main; # location / { # root /usr/share/nginx/html; # index index.html index.htm; # } location / { root /home/VPSUSER/Sinatra/public; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://Sinatra; } }
/home/VPSUSER/Sinatra/unicorn.rb
# coding: utf-8 @dir = "/home/VPSUSER/Sinatra" worker_processes 1 working_directory @dir preload_app true timeout 30 listen "#{@dir}/tmp/Sinatra.sock", :backlog => 64 pid "#{@dir}/tmp/pids/unicorn.pid" stderr_path "#{@dir}/log/unicorn.stderr.log" stdout_path "#{@dir}/log/unicorn.stdout.log"
/home/VPSUSER/Sinatra/config.rb
require './app.rb' run Sinatra::Application
/home/VPSUSER/Sinatra/app.rb
require 'sinatra' require 'sinatra/reloader' require 'sequel' require 'sqlite3' require "date" require "hamlit" set :haml, { escape_html: false } # hamlitを使うのに必要 get '/' do File.read(File.join('public', 'index.html')) end
その他環境
VPSUSER@IP-ADD-RE-SS ~/Sinatra> sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful VPSUSER@IP-ADD-RE-SS ~/Sinatra> ls public/ index.html stylesheets/
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS" nginx version: nginx/1.20.1 unicorn v6.0.0 sinatra (2.1.0)
追記 /var/log/nginx/error.log
2021/11/20 00:19:07 [crit] 34188#34188: *159 connect() to unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock failed (13: Permission denied) while connecting to upstream, client: 103.28.70.206, server: localhost, request: "GET /.env HTTP/1.1", upstream: "http://unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock:/.env", host: "IP.ADD.RE.SS" 2021/11/20 00:19:07 [crit] 34188#34188: *161 connect() to unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock failed (13: Permission denied) while connecting to upstream, client: 103.28.70.206, server: localhost, request: "POST / HTTP/1.1", upstream: "http://unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock:/", host: "IP.ADD.RE.SS" 2021/11/20 01:19:41 [crit] 34188#34188: *163 connect() to unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock failed (13: Permission denied) while connecting to upstream, client: 104.140.188.58, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock:/", host: "IP.ADD.RE.SS:80" 2021/11/20 02:12:12 [crit] 34188#34188: *165 connect() to unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock failed (13: Permission denied) while connecting to upstream, client: 209.141.34.220, server: localhost, request: "GET /config/getuser?index=0 HTTP/1.1", upstream: "http://unix:/home/VPSUSER/Sinatra/tmp/sockets/Sinatra.sock:/config/getuser?index=0", host: "IP.ADD.RE.SS:80" <<中略>>