我正在尝试使用Nginx和Unicorn配置带有SSL的Rails应用程序.我想在本地设置它.为此,我首先使用OpenSSL为Nginx创建了一个自签名证书.我按照文档创建了自签名证书.之后我nginx.conf在http块内部配置了如下:
upstream unicorn_myapp {
# This is the socket we configured in unicorn.rb
server unix:root_path/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name dev.myapp.com;
rewrite ^/(.*) http://dev.myapp.com/$1 permanent;
}
server {
listen 80;
listen 443 ssl;
server_name dev.myapp.com;
ssl on;
ssl_certificate /etc/nginx/ssl/server.pem;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:-ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP;
ssl_session_cache shared:SSL:10m;
root root_path/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://unicorn_myapp;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在本地设置它,并在本地启动Unicorn.我映射 …
我将 nginx 配置为使用 SSL 证书(从 sslforfree.com 获得),但之后发生了奇怪的行为。站点运行良好,但我无法执行任何设计操作,例如,如果有人在使用 SSL 之前登录,则他们无法注销,其他人也无法登录/注册。
我正在 Digital-Ocean 一键式 rails droplet 上配置它。以下观察可能会有所帮助:
nginx.error.log
1 - 客户端在 SSL 握手时关闭连接
2 - SSL_do_handshake() 失败(SSL:错误:1408F10B:SSL 例程:ssl3_get_record:错误的版本号) - 我研究并发现它是由于 SSL 配置中的问题而发生的,我尝试使用 Mozilla 生成的但没有成功。
Rails 服务器日志
1 - 422 无法处理的实体
2 - ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)
配置文件
upstream puma {
server unix:///home/rails/apps/calwinkle/shared/tmp/sockets/calwinkle-puma.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name calwinkle.com www.calwinkle.com;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
# …Run Code Online (Sandbox Code Playgroud)