2015-07-19 85 views
0

時,我做我的本地機器上顯示。不過,我有一個與nginx一起運行的docker容器中的應用程序。我可以用chrome dev工具在assets文件夾中看到application.css & application.js文件,它們不是空的。但是我有一個沒有css/js的頁面,它應該與nginx有關,但我真的很困惑。資產預編譯,但不與美洲獅和nginx的(軌道4)

/var/etc/nginx/nginx.conf:

user app sudo; 

http{ 

    upstream app { 
    server unix:/home/app/puma.sock fail_timeout=0; 
    } 

    server { 
    listen 80 default; 
    root /home/app/app/public; 
    try_files $uri/index.html $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; 
    } 
    } 

    } 

    events {worker_connections 1024;} 

配置/環境/ production.rb:

Rails.application.configure do 
    ... 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 
    config.serve_static_files = true 
    config.assets.js_compressor = :uglifier 
    config.assets.compile = false 
    config.assets.digest = true 
    ... 
    end 

請不要猶豫,建議什麼。 :)

更新: 我剛剛意識到,我在我的控制檯這些2個錯誤:

new:11 Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://localhost/assets/application-5574b338d88d13681ef38b9b0800bc47.css". 
new:12 Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost/assets/application-ea59e17aff7f15a316e3e03d49f3daf4.js". 

回答

0

如果你想nginx的提供給您的靜態資產,你將需要設置config.serve_static_files = false這樣的Rails不會爲你做。

+0

感謝您的迴應,我已將config.serve_static_files更改爲false,但是當將根改爲/ home/app/app/public/assets時,資產甚至不會顯示在chrome工具中。我已經更新了我的問題,請你看看? – bTazi

+0

我完全錯了'js'和'css'文件夾。在你的配置文件中加入'include /etc/nginx/mime.types;'將會消除這些錯誤。 – eddiezane

+0

你如何在你的視圖中包含樣式表和js文件? – eddiezane