webrick 使用 ssl 做什么?
webrick using ssl whats to do?
我有一个 rails 4 应用程序,我想 运行 在 webrick 上使用 SSL。我需要做什么?
我已经为域和启动器添加了 ssl 证书,就像这样
bundle exec rails s -e production -p 3001 --binding=0.0.0.0
现在我得到这个错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at domain.de Port 443
谢谢
为 Apache HTTPS 设置的指令
ProxyPreserveHost On
ProxyRequests On
ServerName domain.de
ServerAlias *.domain.de
ProxyPass / https://subdomain.domain.de:3001/
ProxyPassReverse / https://subdomain.domain.de:3001/
SSLEngine on
大多数人通过从 webrick 切换到 thin(或者更好,unicorn/puma/passenger)来解决这个问题。我不认为 webrick 是为 运行 生产而设计的。
您也可以在 apache 上终止 SSL,这样 webrick 就只处理 http。 (此外,假设 Apache 运行ning 在同一个盒子上,您不需要绑定到 0.0.0.0
。本地主机就可以了,绑定到外部 IP 听起来像是一个安全漏洞。)
如果您真的想保留 webrick 并让它处理 SSL,请按照 this other answer 中所述更改 bin/rails
。
要使用 ssl,只需在 application.rb
中提供
config.force_ssl = true
用于生产的 Webrick 不是 recommended.Right 现在在生产中部署的最好和最简单的方法是将 nginx 与 passenger 或 Puma 一起使用。
带有 Phusion Passenger 的 Nginx
你可以查看官方文档here这是非常简单的步骤。
Gem 乘客
gem "passenger", ">= 5.0.25", require: "phusion_passenger/rack_handler"
Nginx 与 Puma
安装 Puma gem 在您的 Gem 文件中添加这个
gem "puma"
在您的应用程序根目录中创建一个 Procfile。简单 puma 的 Procfile
web: bundle exec puma -C config/puma.rb
goto/create config/initializers/puma.rb
编辑 worker 旁边的值以匹配您的服务器 cores.This 是我的文件的样子。
workers 2 #Change this to match the number of cores in your sever.My server has 2 cors
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
Nginx 文件配置
server {
listen 80;
listen 443 ssl;
server_name servername.com;
ssl_certificate /root/cert_chain.crt;
ssl_certificate_key /root/mycert.key;
# Tell Nginx and Passenger where your app's 'public' directory is
path to your apps public folder
# Turn on Passenger
passenger_enabled on;
passenger_ruby /root/.rbenv/shims/ruby;
# vary encoders
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/json application/x-javascript text/xml text/css text/javascript;
gzip_vary on;
}
我有一个 rails 4 应用程序,我想 运行 在 webrick 上使用 SSL。我需要做什么?
我已经为域和启动器添加了 ssl 证书,就像这样
bundle exec rails s -e production -p 3001 --binding=0.0.0.0
现在我得到这个错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at domain.de Port 443
谢谢
为 Apache HTTPS 设置的指令
ProxyPreserveHost On
ProxyRequests On
ServerName domain.de
ServerAlias *.domain.de
ProxyPass / https://subdomain.domain.de:3001/
ProxyPassReverse / https://subdomain.domain.de:3001/
SSLEngine on
大多数人通过从 webrick 切换到 thin(或者更好,unicorn/puma/passenger)来解决这个问题。我不认为 webrick 是为 运行 生产而设计的。
您也可以在 apache 上终止 SSL,这样 webrick 就只处理 http。 (此外,假设 Apache 运行ning 在同一个盒子上,您不需要绑定到 0.0.0.0
。本地主机就可以了,绑定到外部 IP 听起来像是一个安全漏洞。)
如果您真的想保留 webrick 并让它处理 SSL,请按照 this other answer 中所述更改 bin/rails
。
要使用 ssl,只需在 application.rb
中提供config.force_ssl = true
用于生产的 Webrick 不是 recommended.Right 现在在生产中部署的最好和最简单的方法是将 nginx 与 passenger 或 Puma 一起使用。
带有 Phusion Passenger 的 Nginx
你可以查看官方文档here这是非常简单的步骤。
Gem 乘客
gem "passenger", ">= 5.0.25", require: "phusion_passenger/rack_handler"
Nginx 与 Puma
安装 Puma gem 在您的 Gem 文件中添加这个
gem "puma"
在您的应用程序根目录中创建一个 Procfile。简单 puma 的 Procfile
web: bundle exec puma -C config/puma.rb
goto/create config/initializers/puma.rb
编辑 worker 旁边的值以匹配您的服务器 cores.This 是我的文件的样子。
workers 2 #Change this to match the number of cores in your sever.My server has 2 cors
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
Nginx 文件配置
server {
listen 80;
listen 443 ssl;
server_name servername.com;
ssl_certificate /root/cert_chain.crt;
ssl_certificate_key /root/mycert.key;
# Tell Nginx and Passenger where your app's 'public' directory is
path to your apps public folder
# Turn on Passenger
passenger_enabled on;
passenger_ruby /root/.rbenv/shims/ruby;
# vary encoders
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/json application/x-javascript text/xml text/css text/javascript;
gzip_vary on;
}