繁体   English   中英

Nginx + Chef部署了Rails 4时出现403 Forbidden错误

[英]Rails 4 gets 403 Forbidden error with Nginx + Passenger deployed with Chef

我正在尝试自动构建完整的Rails服务器框,并且一切正常,除了访问Web服务器时收到403 Forbidden消息。

属性:

#jumpsquares directories
default['www_dir']  = '/var/www'
default['jumpsquares_dir']  = '/var/www/jumpsquares'

#rvm
default['rvm']['default_ruby']      = "ruby-2.1.2"
default['rvm']['user_default_ruby'] = "ruby-2.1.2"
default['rvm']['rubies']      = ["ruby-2.1.2"]

#postgresql
default["postgresql"]["pg_hba_defaults"]                 = false
default["postgresql"]["pg_hba"] = [
{ "type"=> "local", "db"=> "all", "user"=> "postgres",   "addr"=> "",             "method"=> "peer" },
{ "type"=> "local", "db"=> "all", "user"=> "all",        "addr"=> "",             "method"=> "md5" },
{ "type"=> "host",  "db"=> "all", "user"=> "all",        "addr"=> "127.0.0.1/32", "method"=> "md5" },
{ "type"=> "host",  "db"=> "all", "user"=> "all",        "addr"=> "::1/128",      "method"=> "md5" }
]
#nginx
default['nginx']['version']      = '1.6.0'
default['nginx']['default_root'] = '/var/www/jumpsquares/public'
default['nginx']['rvm_path'] = "/usr/local/rvm/gems/ruby-2.1.2/bin:/usr/local/rvm/gems/ruby-2.1.2@global/bin:/usr/local/rvm/rubies/ruby-2.1.2/bin"
default['nginx']['configure_flags']    = ["--add-module=/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.42/ext/nginx"]
default['nginx']['source']['modules']  = %w(
nginx::http_ssl_module
nginx::http_gzip_static_module
nginx::passenger
)
default['nginx']['passenger']['version'] = '4.0.42'
default['nginx']['passenger']['root'] = "/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.42"
default['nginx']['passenger']['ruby'] = "/usr/local/rvm/wrappers/ruby-2.1.2/ruby"
default['nginx']['passenger']['gem_binary'] = "/usr/local/rvm/wrappers/ruby-2.1.2/gem"

食谱:

include_recipe "apt"
include_recipe "openssl"
include_recipe "rvm::system"    

include_recipe "postgresql::server"
include_recipe "postgresql::libpq"
include_recipe "postgresql::client"

pg_user "jumpgres" do
  privileges superuser: true, createdb: true, login: true
  password "jump123"
end

pg_database "jumpsquares_prod" do
  owner "jumpgres"
  encoding "UTF-8"
  template "template0"
  locale "en_US.UTF-8"
end

directory node['www_dir'] do
  owner "www-data"
  group "www-data"
  mode 00755
  action :create
end

directory node['jumpsquares_dir'] do
  owner "www-data"
  group "www-data"
  mode 00755
  action :create
end

git node['jumpsquares_dir'] do
  repository "https://github.com/kacole2/JumpSquares.git"
  reference "master"
  action :sync
end

rvm_shell "bundle install" do

     ruby_string "ruby-2.1.2"
     cwd node['jumpsquares_dir']

     code %{
       source /usr/local/rvm/scripts/rvm
       export rvmsudo_secure_path=1
       sudo chown -R www-data:www-data "/var/www"
       rvmsudo gem install passenger -v 4.0.42 --no-rdoc --no-ri
       rvmsudo gem install rake -v 10.3.1 --no-rdoc --no-ri
       rvmsudo bundle install
       rvmsudo rake RAILS_ENV=appliance-production db:setup
       rvmsudo rake RAILS_ENV=appliance-production assets:precompile
       }
   end

include_recipe "nginx::source"
ENV['PATH']="#{node['nginx']['rvm_path']}:#{ENV['PATH']}"

这是生成的nginx文件。 这是/etc/nginx/nginx.conf:

user www-data;
worker_processes  1;
daemon off;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
  worker_connections  1024;
}

http {

  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  access_log    /var/log/nginx/access.log;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_timeout  65;

  gzip  on;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_vary off;
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;
  gzip_min_length  1000;
  gzip_disable     "MSIE [1-6]\.";

  server_names_hash_bucket_size 64;
  types_hash_max_size 2048;
  types_hash_bucket_size 64;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

在/ etc / nginx的/启用的站点 - / 000-默认

server {
  listen   80;
  server_name  chef-cattle12;

  access_log  /var/log/nginx/localhost.access.log;

  location / {
    root   /var/www/jumpsquares/public;
    index  index.html index.htm;
  }
}

/etc/nginx/conf.d/passenger.conf

passenger_root /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.42;
passenger_ruby /usr/local/rvm/wrappers/ruby-2.1.2/ruby;
passenger_max_pool_size 6;
passenger_spawn_method smart-lv2;
passenger_buffer_response on;
passenger_min_instances 1;
passenger_max_instances_per_app 0;
passenger_pool_idle_time 300;
passenger_max_requests 0;

哪个红宝石

administrator@chef-cattle12:~$ which ruby
/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby

administrator@chef-cattle12:~$ passenger-config --root
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.42

文件权限设置正确:

administrator@chef-cattle12:~$ ls -l /var/www
total 4
drwxr-xr-x 14 www-data www-data 4096 May 14 15:29 jumpsquares
administrator@chef-cattle12:~$ ls -l /var/www/jumpsquares/
total 60
drwxr-xr-x 9 www-data www-data 4096 May 14 15:25 app
drwxr-xr-x 2 www-data www-data 4096 May 14 15:25 bin
drwxr-xr-x 5 www-data www-data 4096 May 14 15:25 config
-rw-r--r-x 1 www-data www-data  154 May 14 15:25 config.ru
drwxr-xr-x 3 www-data www-data 4096 May 14 15:25 db
-rw-r--r-x 1 www-data www-data 1313 May 14 15:25 Gemfile
-rw-r--r-x 1 www-data www-data 3583 May 14 15:25 Gemfile.lock
drwxr-xr-x 4 www-data www-data 4096 May 14 15:25 lib
drwxr-xr-x 2 www-data www-data 4096 May 14 15:29 log
drwxr-xr-x 4 www-data www-data 4096 May 14 15:29 public
-rw-r--r-x 1 www-data www-data  254 May 14 15:25 Rakefile
-rw-r--r-x 1 www-data www-data  252 May 14 15:25 README.rdoc
drwxr-xr-x 8 www-data www-data 4096 May 14 15:25 test
drwxr-xr-x 3 www-data www-data 4096 May 14 15:29 tmp
drwxr-xr-x 3 www-data www-data 4096 May 14 15:25 vendor

我已经尝试了处理nginx.conf文件的所有内容。 我尝试过删除索引线,将根移出location子部分,并且进行了更多操作,但似乎无济于事。 日志也没有太大帮助。 任何帮助表示赞赏。

您没有在服务器块和位置块中启用Phusion Passenger。 至少必须在此指定“ passenger_enabled on”。 请参阅Phusion乘客文档。

我必须将这些其他部分添加到我的食谱中,以使乘客正常工作

#the passenger configuration is never enabled with the  OpsCode nginx cookbook. let's add it
ruby_block "add passenger variable" do
  block do
    site_file = Chef::Util::FileEdit.new("#{node["nginx"]["dir"]}/sites-enabled/000-default")
    site_file.insert_line_after_match(/\slocation\s\/\s{/, "    passenger_enabled on;")  
    site_file.write_file
  end
end
#we have to specify the rails environment we want to use since we do not want to use 'production'
ruby_block "add rails environment" do
  block do
    passenger_file = Chef::Util::FileEdit.new("#{node["nginx"]["dir"]}/conf.d/passenger.conf")
    passenger_file.insert_line_if_no_match(/passenger_app_env appliance-production;/, "passenger_app_env appliance-production;")
    passenger_file.write_file
  end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM