gpt4 book ai didi

ruby-on-rails - 使用 nginx 和 unicorn : 403 forbidden error 进行 rails 部署

转载 作者:太空宇宙 更新时间:2023-11-03 17:22:30 25 4
gpt4 key购买 nike

我刚刚设置了一个 VPS (Centos 6.3) 并使用 capistrano 部署了我的应用程序。 VPS 运行 nginx 和 unicorn。访问服务器时出现 403 Forbidden 错误:此行出现在/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"

但是,如果我在 ./public 中将 index.html 添加到我的 Rails 应用程序,则一切正常。这让我觉得路线不起作用。

我还使用 chmod -R 755 * 为/var/www 的所有文件夹设置了权限(从长远来看可能不是最好的主意,但我想将其排除在错误来源之外)。有没有其他方法可以更详细地调试它(error.log 文件没有告诉我任何其他信息)?

非常感谢任何帮助。

这是我的 routes.rb 文件(一切都在本地开发中)

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;
# server_name example.com;
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

# Feel free to change any of the following variables for your app:
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'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'execjs', '~> 1.4.0'
gem 'therubyracer'
gem "less-rails"

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby

gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
gem 'unicorn'

# Deploy with Capistrano
gem 'capistrano'

# To use debugger
# gem 'debugger'


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

最佳答案

我想通了。在 Centos 6.3 上,标准配置存储在/etc/nginx/conf.d/删除此目录中的默认配置后,一切正常。请注意,将自定义 nginx 配置文件符号链接(symbolic link)到/etc/nginx/conf.d 而不是/etc/nginx/sites-enabled 可能更好(我必须在我的系统上创建此目录,然后将其包含在我的/etc 中/nginx/nginx.conf)。

关于ruby-on-rails - 使用 nginx 和 unicorn : 403 forbidden error 进行 rails 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15459447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com