【发布时间】:2023-04-10 19:41:04
【问题描述】:
我有一个使用 AWS 弹性 beanstalk 负载均衡器在 puma 和 nginx 上运行的 rails 应用程序。我配置了 AWS 证书,它在 http 和 https 上都能正常工作。
但是,如果我在 config/environments/production.rb 上启用 config.force_ssl = true,我开始收到以下错误:
在 http:连接已重置
在 https 上:安全连接失败。页面加载时,与服务器的连接已重置。
这是我从 awslabs/elastic-beanstalk-samples here 获得的 nginx 配置文件的内容:
.ebextensions/nginx.config
files:
"/opt/elasticbeanstalk/support/conf/webapp_healthd.conf":
owner: root
group: root
mode: "000644"
content: |
upstream my_app {
server unix:///var/run/puma/my_app.sock;
}
server {
listen 80;
server_name _ localhost; # need to listen to localhost for worker tier
location / {
set $redirect 0;
if ($http_x_forwarded_proto != "https") {
set $redirect 1;
}
if ($http_user_agent ~* "ELB-HealthChecker") {
set $redirect 0;
}
if ($redirect = 1) {
return 301 https://$host$request_uri;
}
proxy_pass http://my_app; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /assets {
alias /var/app/current/public/assets;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
location /public {
alias /var/app/current/public;
gzip_static on;
gzip on;
expires max;
add_header Cache-Control public;
}
}
container_commands:
99_restart_nginx:
command: "service nginx restart || service nginx start"
【问题讨论】:
标签: ruby-on-rails amazon-web-services nginx amazon-elastic-beanstalk