簡體   English   中英

使用Chef Solo為Nginx配置Rails

[英]Configuring Nginx for rails using Chef Solo

我正在嘗試配置一個CentOS服務器來托管我的Rails應用程序。 我正在使用chef solo來配置nginx,但是當我嘗試重新啟動服務器時,出現錯誤,提示unknown directive upstream

錯誤

 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

nginx.rb

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

nginx.conf.erb

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;
}

您安裝的Nginx的版本很可能太舊或沒有編譯上游模塊。無論哪種情況,Chef都不參與,nginx本身拒絕了您的配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM