This is currently the most popular solution to serve rails apps and is used by many big companies like Github, tweet, 37signals and so on. Also, it is very easy to setup in this way.
Config unicorn Install gem unicorn:Put gem ‘unicorn’ in Gemfile
then bundle install
Vim config/unicorn.rb under your rails app root dir.
content:
# The ONLY two things you should change, if you don’t need any specialty. app_name = "your_app_name" number_of_app_instances = 2 # Set the working application directory. This should be your rails app root dir, not the public dir app_root = File.expand_path(File.dirname(__FILE__) + "/..") working_directory app_root # File to store unicorn pid # pid "/path/to/pids/unicorn.pid" pid "#{app_root}/tmp/pids/unicorn.pid" # Path to logs # stderr_path "/path/to/log/unicorn.log" # stdout_path "/path/to/log/unicorn.log" stderr_path "#{app_root}/log/unicorn.log" stdout_path "#{app_root}/log/unicorn.log" # Unicorn socket listen "/tmp/unicorn.#{app_name}.sock" # Number of processes worker_processes number_of_app_instances # Time-out timeout 30Nginx config Install nginx
sudo apt-get update sudo apt-get install nginx
Default nginx config file would be located in /etc/nginx
Nginx config fileAdd a file in sites_available and put content:
upstream app { # Path to Unicorn SOCK file, as defined previously server unix:/tmp/unicorn.your_app_name.sock fail_timeout=0; } # configure server for your app server { listen 80; server_name yourdomain.com www.yourdomain.com; root /path/to/your/rails/root/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri @app; location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app; } }Make a soft link in sites-enabled to the above nginx config file Reload nginx
sudo service nginx restart
Start serving Compile assets: rake assets:precompileIf you only want to server your app in development environment, you don"t need this step.
Start unicorn in productionbundle exec unicorn -c config/unicorn.rb -E production
更多文章請(qǐng)?jiān)L問(wèn)個(gè)人博客
作者:鄒小創(chuàng)
Github
微博
郵件:happystriving@126.com
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/39211.html
摘要:最近總是在配置阿里云的服務(wù)器,遇到不少問(wèn)題,現(xiàn)小結(jié)一下,供大家參考阿里云的一鍵安裝全環(huán)境下載一鍵安裝全環(huán)境壓縮包上傳至服務(wù)器,解壓執(zhí)行腳本,具體步驟詳見(jiàn)這里任意選擇一種方法執(zhí)行腳本方法一方法二安裝與指定的版本安裝與指定的版本注意安 最近總是在配置阿里云的服務(wù)器,遇到不少問(wèn)題,現(xiàn)小結(jié)一下,供大家參考~~ 1、阿里云的一鍵安裝web全環(huán)境 下載一鍵安裝web全環(huán)境 sh.zip 壓縮...
摘要:環(huán)境準(zhǔn)備版本版本版本版本版本因系列的版本是的,已經(jīng)支持,所以不必升級(jí)版本。 環(huán)境準(zhǔn)備 python版本2.6 git版本 1.8.4.1 ruby版本ruby-2.0.0-p353 gitlab-shell版本 v1.8.0 gitlab版本6.4.3 因centos6系列的python版本是2.6的,已經(jīng)支持,所以不必升級(jí)python版本。 在centos5下面需要升級(jí)pyt...
摘要:是一個(gè)能快速搭建環(huán)境的工具,它能快速的將和部署到你的服務(wù)器中,是部署環(huán)境就如同環(huán)境那樣簡(jiǎn)單快速,讓人愉悅。在上跑一般只有在生產(chǎn)環(huán)境下才會(huì)使用,因而默認(rèn)下就是環(huán)境設(shè)置為生產(chǎn)環(huán)境,而初始化時(shí)默認(rèn)沒(méi)有對(duì)生產(chǎn)環(huán)境進(jìn)行密鑰配置。 passenger passenger是一個(gè)能快速搭建web環(huán)境的工具,它能快速的將nginx和passenger部署到你的服務(wù)器中,是部署ruby環(huán)境就如同php環(huán)...
摘要:環(huán)境確認(rèn)確認(rèn)用見(jiàn)出。環(huán)境変數(shù)設(shè)定見(jiàn)。生成値設(shè)定正常動(dòng)作確認(rèn)。環(huán)境変數(shù)渡場(chǎng)合定番。 production 環(huán)境で、なぜか Rails アプリケーションの畫面が真っ白になってしまった。 — 環(huán)境 — Rails 4.1 Unicorn エラーログを確認(rèn) unicorn のエラーログを確認(rèn)しますと… $ tail -f log/unicorn-stderr.log E, [2014-...
閱讀 2601·2021-11-15 11:38
閱讀 2618·2021-11-04 16:13
閱讀 17981·2021-09-22 15:07
閱讀 1014·2019-08-30 15:55
閱讀 3261·2019-08-30 14:15
閱讀 1663·2019-08-29 13:59
閱讀 3207·2019-08-28 18:28
閱讀 1575·2019-08-23 18:29