艱難完成 nginx + puma 部署 rails 4的詳細(xì)記錄
花了兩周時(shí)間 Google 部署方法,找的的許多方法都沒(méi)有用,最終被我用控制變量法,一條一條修改配置文件修改成功了。
首先是 /etc/nginx/vhosts/limlog.sloger.info.conf 和 config/puma.rb
# # /etc/nginx/vhosts/limlog.sloger.info.conf # upstream limlog { server unix:///tmp/limlog.sock; } server { listen 80; server_name limlog.sloger.info; root /srv/http/limlog.sloger.info/public; access_log /var/log/nginx/limlog-access.log; error_log /var/log/nginx/limlog-error.log info; location / { expires max; add_header Cache-Control public; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://limlog; } location ~ ^/assets/ { expires 1y; gzip_static on; add_header ETag ""; add_header Cache-Control public; break; } }
#!/usr/bin/env ruby -w # # config/puma.rb # rails_env = ENV['RAILS_ENV'] || 'development' threads 4, 4 bind 'unix:///tmp/limlog.sock' pidfile '/tmp/limlog.pid' state_path '/tmp/limlog.state' activate_control_app
把 nginx 配置文件里的 root server_name upstream 修改成你的就行了,每個(gè)文件放在哪里,文件頭部注釋里面寫(xiě)了。
然后是修改 config/environmens/production.rb
18 行 false 改為 true
# Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = true
29 行取消注釋
# Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
然后是 app/controller/application_controller
第二行參數(shù) with: :exception 去掉
protect_from_forgery
然手是 secret_key_base
我的做法是創(chuàng)建一個(gè)文件 env.sh
# 使用 rake secret 生成 key, 然后粘貼在 = 后面 export SECRET_KEY_BASE= # 下面可以 export 各種環(huán)境變量
啟動(dòng)
啟動(dòng)或者重啟 nginx
導(dǎo)入環(huán)境變量 source env.sh
啟動(dòng) rails bundle exec -C config/puma.rb -e production
現(xiàn)在就部署完畢了, 最令人頭疼的 assets 也解決了~
相關(guān)文章
Ruby實(shí)現(xiàn)網(wǎng)頁(yè)圖片抓取
本文給大家分享的是個(gè)人使用ruby編寫(xiě)的抓取網(wǎng)頁(yè)圖片的代碼,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2016-04-04編寫(xiě)Ruby腳本來(lái)對(duì)Twitter用戶的數(shù)據(jù)進(jìn)行深度挖掘
這篇文章主要介紹了編寫(xiě)Ruby腳本來(lái)對(duì)Twitter用戶的數(shù)據(jù)進(jìn)行深度挖掘的一些例子,通過(guò)調(diào)用Twitter API來(lái)實(shí)現(xiàn)各種功能(內(nèi)地注意墻),需要的朋友可以參考下2015-11-11Ruby單元測(cè)試框架TestUnit的替代者M(jìn)iniTest介紹
這篇文章主要介紹了Ruby單元測(cè)試框架TestUnit的替代者M(jìn)iniTest介紹,本文先是對(duì)比了TestUnit、MiniTest的優(yōu)劣,然后給出了MiniTest的使用示例,需要的朋友可以參考下2015-03-03Linux下Redis數(shù)據(jù)庫(kù)的安裝方法與自動(dòng)啟動(dòng)腳本分享
這篇文章主要介紹了Linux下Redis數(shù)據(jù)庫(kù)的安裝方法與自動(dòng)啟動(dòng)腳本分享,自動(dòng)啟動(dòng)腳本分別針對(duì)CentOS和Ubuntu系統(tǒng)來(lái)給出了編寫(xiě)示例,需要的朋友可以參考下2016-05-05Ruby實(shí)現(xiàn)批量對(duì)文件增加前綴代碼分享
這篇文章主要介紹了Ruby實(shí)現(xiàn)批量對(duì)文件增加前綴代碼分享,本文給出實(shí)現(xiàn)代碼、使用方法、使用示例等內(nèi)容,需要的朋友可以參考下2015-01-01