2011-12-30 28 views
7

Tôi đang chạy đường ray 3.1 trong chế độ phát triển trên Ubuntu với sqlite. Các máy chủ rails đang chạy trên cổng 3000, và tôi đã nginx thiết lập để proxy_pass cổng 80 và 443 đến cổng 3000. khi tôi đặt config.force_ssl = true vào Application.rb của tôi và khởi động lại máy chủ đường ray, tôi nhận được một lỗi trông giống như:SSL với Rails 3.1: config.force_ssl = true không hoạt động ở chế độ phát triển

Secure Connection Failed 
    An error occurred during a connection to localhost:3000. 

    SSL received a record that exceeded the maximum permissible length. 

    (Error code: ssl_error_rx_record_too_long) 

    The page you are trying to view can not be shown because the authenticity of the received data could not be verified. 
    Please contact the web site owners to inform them of this problem. Alternatively, use the command found in the help menu to report this broken site. 

Khi tôi đổi lại thành config.force_ssl = false và khởi động lại máy chủ đường ray, tôi vẫn gặp lỗi, [2011-12-30 09:48:02] ERROR bad URI 9W\x0Fe���h=9��ݔ|�#��)�/6\x00\x00H\x00��'. trong bảng điều khiển đường ray. Điều này biến mất và mọi thứ trở lại bình thường nếu tôi cũng xóa bộ nhớ cache của trình duyệt. Nhưng làm thế nào để tôi nhận được force_ssl = true để hoạt động?

Dưới đây là một phần của Application.rb tôi:

module Regi 
     class Application < Rails::Application 
     # Settings in config/environments/* take precedence over those specified here. 
     # Application configuration should go into files in config/initializers 
     # -- all .rb files in that directory are automatically loaded. 
     config.generators do |g| 
      g.template_engine :haml 
     end 
     config.force_ssl = true 
     end 
    end   

Và đây là của tôi/etc/nginx/sites-enabled/default:

server { 
    #listen 80; ## listen for ipv4; this line is default and implied 
    #listen [::]:80 default ipv6only=on; ## listen for ipv6 

    root /usr/share/nginx/www; 
    index index.html index.htm; 

    # Make site accessible from http://localhost/ 
    server_name localhost; 

    location/{ 
      # First attempt to serve request as file, then 
      # as directory, then fall back to index.html 
      proxy_pass  http://localhost:3000; 
      try_files $uri $uri/ /index.html; 
    } 


    #error_page 404 /404.html; 

    # redirect server error pages to the static page /50x.html 
    # 
    #error_page 500 502 503 504 /50x.html; 
    #location = /50x.html { 
    #  root /usr/share/nginx/www; 
    #} 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    #location ~ \.php$ { 
    #  fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    #  # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 
    # 
    #  fastcgi_pass 127.0.0.1:9000; 
    #  fastcgi_index index.php; 
    #  include fastcgi_params; 
    #} 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    #location ~ /\.ht { 
    #  deny all; 
    #} 
} 

# HTTPS server 
server { 
    listen  443; 
    server_name localhost; 

    #charset koi8-r; 

    #access_log logs/host.access.log main; 
    ssl on; 
    ssl_certificate /usr/local/conf/ssl_keys/server.crt; 
    ssl_certificate_key /usr/local/conf/ssl_keys/server.key; 

    location/{ 
     proxy_pass  http://localhost:3000; 
     proxy_set_header X-Real-IP $remote_addr; 
     # root html; 
     # index index.html index.htm; 
    } 

    #error_page 404    /404.html; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root html; 
    } 
} 

Trả lời

2

tôi đã gặp phải những lỗi chính xác cùng tin nhắn khi tôi cấu hình một máy chủ nginx ssl.Đó là bởi vì tôi đã không có st crt và key.Và trong tập tin cấu hình nginx của bạn, tôi đã thông báo đã có crt và key.So bạn có chắc chắn cả crt và key là ok ? Nếu bạn không chắc chắn, bạn có thể thử liên kết sau để tạo crt tự gán. http://devcenter.heroku.com/articles/ssl-certificate-self

p.s. Tôi muốn chắp thêm câu trả lời này dưới dạng một nhận xét nhỏ, nhưng có vẻ như tôi không có quyền này

Các vấn đề liên quan