I just installed VPS (Centos 6.3) and deployed my application using capistrano. VPS runs nginx and unicorn. When visiting the server, I get 403 Forbidden error: this line appears in /var/log/nginx/error.log:
*5 directory index of "/var/www/current/public/" is forbidden, client: xxxxx, server: xxx, request: "GET / HTTP/1.1", host: "xxxx"
However, if I add index.html to my rails application. / public, everything will work without problems. This makes me think that routes do not work.
I also set permissions for all / var / www folders using chmod -R 755 * (probably not a good idea in the end, but wanted to eliminate this as a source of error). Is there any other way to debug this in more detail (the error.log file tells me nothing)?
Any help is greatly appreciated.
This is my routes.rb file (everything works locally in development)
MyTest::Application.routes.draw do
root :to => 'welcome#index'
end
nginx.conf:
upstream unicorn {
server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}
server {
listen 80 default deferred;
root /var/www/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 5;
}
unicorn_init.sh:
#!/bin/sh
set -e
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/var/www/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=
set -u
OLD_PIN="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "$1" - $AS_USER
fi
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
run "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;;
upgrade)
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
while test -s $OLD_PIN && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
if test $n -lt 0 && test -s $OLD_PIN
then
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
exit 1
fi
exit 0
fi
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
run "$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
exit 1
;;
esac
, , Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'pg'
gem 'execjs', '~> 1.4.0'
gem 'therubyracer'
gem "less-rails"
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'unicorn'
gem 'capistrano'
gem "haml", "~> 4.0.0"
gem 'twitter-bootstrap-rails', '~> 2.2.6'
gem "simple_form", "~> 2.1.0"
unicorn.rb:
root = "/var/www/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.blog.sock"
worker_processes 4
timeout 30