Ruby on rails 使用Chef Solo为rails配置Nginx

Ruby on rails 使用Chef Solo为rails配置Nginx,ruby-on-rails,ruby,nginx,chef-infra,chef-solo,Ruby On Rails,Ruby,Nginx,Chef Infra,Chef Solo,我正在尝试配置CentOS服务器来承载我的rails应用程序。我正在使用chef solo来配置nginx,但当我尝试重新启动服务器时,我收到一个错误消息,上面写着unknown directive up 错误 nginx.rb nginx.conf.erb 上游美洲狮{ 服务器unix:///home/deploy/apps//shared/tmp/sockets/-puma.sock; } 服务器{ 监听80默认_服务器延迟; #server_name example.com; root/h

我正在尝试配置CentOS服务器来承载我的rails应用程序。我正在使用chef solo来配置nginx,但当我尝试重新启动服务器时,我收到一个错误消息,上面写着
unknown directive up

错误 nginx.rb nginx.conf.erb
上游美洲狮{
服务器unix:///home/deploy/apps//shared/tmp/sockets/-puma.sock;
}
服务器{
监听80默认_服务器延迟;
#server_name example.com;
root/home/deploy/apps//current/public;
access\u log/home/deploy/apps//current/log/nginx.access.log;
error\u log/home/deploy/apps//current/log/nginx.error.log info;
地点^ ~/资产/{
gzip_静态开启;
最大值;
添加_头缓存控制公共;
}
试试看文件$uri/index.html$uri@puma;
地点@puma{
proxy\u set\u header X-Forwarded-For$proxy\u add\u X\u Forwarded\u For;
代理设置头主机$http\U主机;
代理_重定向关闭;
代理通行证http://puma;
}
错误\u第500页502 503 504/500.html;
客户最大身体尺寸10米;
保持激活超时10;
}

您安装的Nginx版本很可能太旧或没有编译上游模块。在这两种情况下,Chef都没有参与,nginx本身拒绝了您的配置

 Error executing action `restart` on resource 'service[nginx]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '6'
    ---- Begin output of /sbin/service nginx restart ----
    STDOUT: 
    STDERR: nginx: [emerg] unknown directive "upstream" in /etc/nginx/nginx.conf:5
    nginx: configuration file /etc/nginx/nginx.conf test failed
    ---- End output of /sbin/service nginx restart ----
    Ran /sbin/service nginx restart returned 6
package 'nginx'

# execute 'sudo mkdir /etc/nginx/sites-enabled'
directory '/etc/nginx/sites-enabled' do
  owner 'deploy'
  group 'wheel'
  mode '0755'
  action :create
end

# remove default nginx config
default_path = '/etc/nginx/sites-enabled/default'
execute "rm -f #{default_path}" do
  only_if { File.exist?(default_path) }
end

# start nginx
service 'nginx' do
  supports [:status, :restart]
  action :start
end

# # set custom nginx config
# template "/etc/nginx/sites-enabled/#{node['app']}" do
#   source 'nginx.conf.erb'
#   mode 0644
#   owner node['user']['name']
#   group node['group']
#   notifies :restart, 'service[nginx]', :delayed
# end

template '/etc/nginx/nginx.conf' do
  source 'nginx.conf.erb'
  mode 0644
  owner node['user']['name']
  group node['group']
  notifies :restart, 'service[nginx]', :delayed
end
upstream puma {
  server unix:///home/deploy/apps/<%= node['app'] %>/shared/tmp/sockets/<%= node['app'] %>-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/deploy/apps/<%= node['app'] %>/current/public;
  access_log /home/deploy/apps/<%= node['app'] %>/current/log/nginx.access.log;
  error_log /home/deploy/apps/<%= node['app'] %>/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}