独角兽和Nginx的配置

独角兽

gem 'unicorn'
$ bundle install

手动创建设置文件。

$ touch config/unicorn.rb

在设定文件中写下以下内容。

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
      ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
      ActiveRecord::Base.establish_connection
end
```

``` terminal:unicornの実行(動作確認)
$ bundle exec unicorn_rails -c config/unicorn.rb
$ bundle exec unicorn_rails -c config/unicorn.rb -E development -D
ctrl + q
unicorn Address already in use)
$ ps aux |grep 8080   # 8080のプロセスIDを表示
$ kill [プロセスID]     # 8080のプロセスをKillする

Nginx是一个开源的网页服务器软件和反向代理服务器,被广泛用于加速静态和动态内容的传输,以提高网站的性能和可靠性。

用Homebrew安装nginx。

$ brew install nginx
$ vi /usr/local/etc/nginx/nginx.conf
    server { 
        listen       80; 
        server_name  localhost; 
$ brew info nginx
$ sudo brew services start nginx
※どうやら brew services start nginxとコマンドを実行しておけば次回以降、Mac 再起動時に Nginx が自動起動される様子。

もしくは、起動できない場合は
$ sudo nginx
$ brew services stop nginx

独角兽与Nginx的协调设置

・稍后,我会写的。

确认web服务器已启动

如果能够访问的话,请尝试访问以下链接:
http://localhost:80
=>如果能够访问成功就表示OK

广告
将在 10 秒后关闭
bannerAds