【问题标题】:Nginx cannot serve Rails files in Unicorn + Vagrant setupNginx 无法在 Unicorn + Vagrant 设置中提供 Rails 文件
【发布时间】:2013-09-15 22:01:53
【问题描述】:

我正在尝试在运行带有 Unicorn + Nginx 的 Ubuntu 12.04 的 Vagrant VM 中设置本地 Rails 3.2 开发环境。我安装了带有软链接的 nginx,如下所示:

sudo apt-get install nginx
Create symlink for nginx conf file for dactarkhoj
cd /etc/nginx/sites-enabled
sudo ln -s /vagrant/config/nginx.conf dactarkhoj.conf
sudo service nginx start

独角兽也设置好了,我用它启动了

unicorn_rails  -c /vagrant/config/unicorn.rb -D

现在由于某种原因,当我打开浏览器时,我只收到“欢迎使用 nginx”消息,而不是 rails 应用程序。造成这种情况的可能陷阱是什么?

nginx.conf文件是

upstream unicorn {
  server unix:/tmp/unicorn.dactarkhoj.sock fail_timeout=0;
}

server {
  listen 80 default;
  root /vagrant/public;
  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
}

独角兽的conf文件是

worker_processes 4

rails_root = File.expand_path('../..', __FILE__)
working_directory rails_root

listen '/tmp/unicorn.dactarkhoj.sock'

pid File.expand_path('tmp/pids/unicorn.pid', ENV['RAILS_ROOT'])

# combine REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
preload_app true

# Set the path of the log files inside the log folder of the testapp
stderr_path "/vagrant/log/unicorn.stderr.log"
stdout_path "/vagrant/log/unicorn.stdout.log"

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!

  old_pid = "#{ server.config[:pid] }.oldbin"
  unless old_pid == server.pid
    begin
      Process.kill :QUIT, File.read(old_pid).to_i
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

【问题讨论】:

  • 你用的是3.2,好吗?您是否使用资产管道?
  • @RodrigoOliveira 是的,它已启用。只是将其保留为默认设置。

标签: ruby-on-rails nginx unicorn


【解决方案1】:

正如你所说,这是你的设置:

Create symlink for nginx conf file for dactarkhoj
cd /etc/nginx/sites-enabled
sudo ln -s /vagrant/config/nginx.conf dactarkhoj.conf
sudo service nginx start

我认为你应该将 dactarkhoj.conf 复制到 /etc/nginx/sites-enabled/default 并覆盖它。

【讨论】:

    猜你喜欢
    • 2017-01-07
    • 1970-01-01
    • 2015-08-15
    • 2014-04-13
    • 2012-11-08
    • 2016-02-18
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    相关资源
    最近更新 更多