config.i18n.fallbacks = true
。production 下的語系順序才會乖乖實現。
config.i18n.fallbacks = true
。(轉自: ROR實戰聖經) |
user deployer; # 定義操作 nginx 的使用者 worker_processes 1; # 定義 worker 的數量 error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; gzip on; gzip_http_version 1.0; gzip_comp_level 2; gzip_proxied any; gzip_vary off; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml; gzip_min_length 1000; gzip_disable "MSIE [1-6]\."; server_names_hash_bucket_size 64; types_hash_max_size 2048; types_hash_bucket_size 64; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
upstream unicorn { server 127.0.0.1:8080 fail_timeout=0; } server { listen 80 default deferred; server_name flytutor.com; root /var/www/flytutor/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://unicorn; } } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }
upstream flytutor.com { server 192.168.0.111:8080 weight=3; server 192.168.0.222:8080 weight=2; server 192.168.0.333:8080 weight=3; }其中 weight 代表的是「被配發 request 的權重」,當 weight 越高的時候被分配到的機率越大,可以做 loading balance。
upstream unicorn { server unix:/tmp/unicorn.sock fail_timeout=0; }
app_root = "/var/www" app_name = "flytutor" listen "127.0.0.1:10101" #, :backlog => 2048 #這邊要跟nginx虛擬主機檔中upstream內定義的務必一樣 worker_processes 2 #看情況開 preload_app false timeout 30 module Rails class <<self def root File.expand_path(__FILE__).split('/')[0..-3].join('/') end end end _working_directory = File.join(app_root, app_name) working_directory _working_directory logs_path = "#{_working_directory}/log" pid "#{_working_directory}/tmp/pids/unicorn.pid" stderr_path "#{logs_path}/unicorn.stderr.log" stdout_path "#{logs_path}/unicorn.stdout.log" GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{Rails.root}/tmp/pids/unicorn.pid.oldbin" if File.exists?(old_pid) && server.pid != old_pid begin Process.kill("QUIT", File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH puts "Send 'QUIT' signal to unicorn error!" end end end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
/usr/bin/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D
。但現在 unicorn 官方已經不建議使用這種作法而是直接改用 unicorn
來啟動/重啟 unicorn。$ gem install vagrant #安裝 vagrant $ vagrant box add ubuntu http://cloud-images.ubuntu.com/vagrant/quantal/current/quantal-server-cloudimg-i386-vagrant-disk1.box #安裝新的 Vagrant Package。這裡的 ubuntu 是一個預先做好的空的 ubuntu 12.10 (intel-based) $ vagrant init ubuntu $ vagrant upbox 檔可以在 http://www.vagrantbox.es/ 下載
config.vm.network :hostonly, "33.33.33.33"
將ip改成自己想要的ip,這裡以 "33.33.33.33" 為例。修改完後要執行 vangrant reload
[default] Failed to connect to VM!當出現上面的錯誤訊息時,可以照 http://vagrant.wikia.com/wiki/Usage 上的步驟來排除,基本上就是將 Vagrantfile 中的
Failed to connect to VM via SSH. Please verify the VM successfully booted
by looking at the VirtualBox GUI.
config.vm.boot_mode = :gui
設定打開。再重新 vagrant up
,在產生的 GUI 中輸入 sudo dhclient eth0
。[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.