2014-01-14 81 views
2

我設置了我的導軌應用程序,效果很好。不幸的是,在該網站的https://版本中,我的資產沒有被投放......對於這種情況發生的原因有任何想法?所有資產都通過http://提供服務,但無一通過https://使用NGINX和Unicorn在Rails 3應用程序中使用資產VIA SSL

幫助?

============= CODE ==============

upstream unicorn { 


server unix:/tmp/unicorn.XXX.sock fail_timeout=0; 
} 

server { 
    listen 80 default; 
    server_name example.com; 
    root /home/deployer/apps/XXX/current/public; 

location ^~ /assets/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
} 

try_files $uri/index.html $uri @unicorn; 

location @unicorn { 
    proxy_set_header X-Forwarded-Proto http; 
    proxy_pass http://unicorn; 
} 
error_page 500 502 503 504 /500.html; 
client_max_body_size 5G; 
keepalive_timeout 10; 
send_timeout 240; 
sendfile_max_chunk 5m; 
} 

server { 
    listen 443; 
    server_name example.com; 
    root /home/webuser/apps/XXX/current/public; 

location ^~ /assets/ { 
    gzip_static on; 
    expires max; 
    add_header Cache-Control public; 
} 

try_files $uri @non-ssl-redirect @unicorn; 

location @unicorn { 
    proxy_set_header X-Real-IP  $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Proto https; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://unicorn; 
} 
error_page 500 502 503 504 /500.html; 
client_max_body_size 5G; 
keepalive_timeout 10; 

ssl on; 
ssl_certificate   /etc/nginx/ssl/server.crt; 
ssl_certificate_key  /etc/nginx/ssl/server.key; 
ssl_protocols   SSLv3 TLSv1 TLSv1.1 TLSv1.2; 
ssl_ciphers    ALL:-ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP; 
ssl_session_cache  shared:SSL:10m; 

send_timeout 240; 
sendfile_max_chunk 5m; 
} 

回答

2

這聽起來像你的資產主機配置是硬連線到http。當您通過https查看頁面,但通過http加載資源時,許多瀏覽器會阻止該資產或顯示警告。

解決此問題的最簡單方法是設置一個不包含協議的Rails asset_host,該協議應該繼承從其加載的頁面的協議。

例如:

# Use just the asset host domain name for Rails pages 
config.action_controller.asset_host = "assets.mycompany.com" 
# Specify HTTP for ActionMailer messages, since they don't have a protocol to inherit 
config.action_mailer.asset_host = "http://assets.mycompany.com" 

如果正確,包括您的資產與https協議,但他們無法加載 - 很可能有您的資產和主機名之間的SSL證書名稱不匹配SSL證書。例如,如果您使用自定義域名直接從S3提供資產,則S3 SSL證書(* .s3.amazonaws.com)將無法匹配assets.yourcompany.com,並導致SSL錯誤,導致資產無法加載。

在這種情況下,唯一的解決方法是使用資產的主機或CDN,允許自定義的SSL證書來匹配你的主機名,或恢復到公共主機名,你的供應商的SSL證書相匹配。

+0

這適用於像我的application.css文件以及? –

+0

我在上面添加了我的nginx.conf文件(有一些遺漏)。 –

相關問題