2017-03-09 69 views
0

我在我的rails項目中使用ckeditor WYSIWYG text editor。特別是:我在生產模式下配置圖片上傳時遇到問題。Rails:ckeditor gem不能在nginx和乘客的生產模式下工作

它在開發模式下工作得很好,甚至在使用Puma時在生產模式下也能工作。當我點擊上傳照片並點擊Browse Server按鈕。它立即尋找照片,我期望他們:在/assets/ckeditor_assets/pictures

問題是讓它在nginx的生產模式下工作。當我在生產模式下使用nginx時:它返回一個404 Not Found錯誤消息。我看了看我的服務器日誌,這裏是這樣說的:

「的/ var/WWW/MYAPP/CKEditor的/圖片」 失敗(2:沒有這樣的文件或目錄)

所以對於一些因爲它試圖在我的公共目錄中找到一個ckeditor目錄(因爲這是我公共目錄的符號鏈接)。我甚至不知道爲什麼ckeditor正在尋找一個ckeditor目錄,而不是在我的應用程序public/assets/ckeditor_assets目錄中查找。

我試圖通過在我的公共目錄中創建一個ckeditor目錄,然後在其中放置一個pictures目錄來解決此問題。但是,當我這樣做時,我得到了一個403 Forbidden錯誤。

我也注意到,在config/initializers/ckeditor.rb文件中有這樣一行:

# Customize ckeditor assets path 
# By default: nil 
#config.asset_path = "http://www.example.com/assets/ckeditor/" 

所以只是爲了給它一個鏡頭我硬編碼,我想CKEditor的去獲取圖片,可惜沒有工作。

任何建議,請讓我知道。謝謝!我會繼續前進,顯示情況下我ckeditor::picture模型文件,它提供的線索:

class Ckeditor::Picture < Ckeditor::Asset 
    has_attached_file :data, 
    :url => "/assets/ckeditor_assets/pictures/:id/:style_:basename.:extension", 
    :path => ":rails_root/public/assets/ckeditor_assets/pictures/:id/:style_:basename.:extension", 
    :styles => { :content => '800>', :thumb => '118x100#' } 

    validates_attachment_presence :data 
    validates_attachment_size :data, :less_than => 2.megabytes 
    validates_attachment_content_type :data, :content_type => /\Aimage/ 

    def url_content 
    url(:content) 
    end 
end 

回答

0

我的一個哥們了它。原來這只是nginx.conf文件中所需的配置。我正在使用nginx和乘客。

ck_editor發送到ckeditor/pictures的請求,而不是MYAPP/ckeditor/pictures。基本上:它忽略了你的應用的相對路徑(通過乘客)。我剛剛更新的位置正則表達式塊,像這樣:

# nginx.conf 
... 
location ~ ^/(RELATIVE_PATH_FOR_APP|ckeditor/pictures)(/.*|$) { 
    ... 
} 

另一種是一個可能能夠通過重寫一些the ckeditor config.js file發現配置放棄位置塊內的ckeditor/pictures正則表達式。這樣您就可以在應用程序級別指定ck_editor路由而不是服務器級別。