nginx - 利用 Carrierwave 上傳的圖片在 production 環(huán)境中不顯示
問題描述
我項(xiàng)目中Uploader的代碼如下:
class PhotoUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick process :resize_to_fit => [nil, 600] version :thumb do process :resize_to_fill => [150,150] end # Choose what kind of storage to use for this uploader: storage :file def store_dir 'uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}' end def cache_dir '#{Rails.root}/tmp/uploads' end def extension_white_list %w(jpg jpeg gif png) end def filename if original_filename @name ||= Digest::MD5.hexdigest(current_path) '#{@name}.#{file.extension}' end endend
在production.rb中,設(shè)置config.serve_static_assets = false。
利用Capistrano部署到Nginx + Passenger的生產(chǎn)環(huán)境中后,每次上傳圖片后會(huì)根據(jù)uploader的設(shè)置生成兩份,就像這樣:
其中,訪問第一個(gè)圖片可以正常顯示,訪問第二個(gè)(version :thumb)處理過的圖片無法顯示,報(bào)出:
ActionController::RoutingError (No route matches [GET] '/uploads/picture/photo/49/thumb_6d9596c7449d3714eadb74b9c71beec2.jpg')
這樣的錯(cuò)誤,而實(shí)際上這里面的thumb_6d9596c7449d3714eadb74b9c71beec2.jpg是存在于該路徑下的。
所以,這是哪里出了錯(cuò)?該怎么辦?
問題解答
回答1:可以通過 photo.url(:thumb) 試試
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.3. docker - 如何修改運(yùn)行中容器的配置4. python3.x - python連oanda的模擬交易api獲取json問題第五問5. nignx - docker內(nèi)nginx 80端口被占用6. css3 - 沒明白盒子的height隨width的變化這段css是怎樣實(shí)現(xiàn)的?7. javascript - webpack熱加載配置不生效8. javascript - QWebEngineView 如何爬 angular 的動(dòng)態(tài)數(shù)據(jù)?9. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類10. java - instance method中 static后的<K>是什么意思?
