加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

使用opsworks nginx和ELB终止SSL时强制使用HTTPS

发布时间:2020-12-13 20:58:24 所属栏目:Nginx 来源:网络整理
导读:使用通过Unicorn / nginx图层提供服务的Rails应用程序的Opsworks标准设置/食谱. SSL在Elastic Load Balancer处终止-因此从ELB到rails应用程序的流量始终为http.到现在为止还挺好.我想将http://domain.com的任何请求重定向到https://domain.com ELB有两个侦听

使用通过Unicorn / nginx图层提供服务的Rails应用程序的Opsworks标准设置/食谱. SSL在Elastic Load Balancer处终止-因此从ELB到rails应用程序的流量始终为http.到现在为止还挺好.我想将http://domain.com的任何请求重定向到https://domain.com

ELB有两个侦听器-一个带有端口80,另一个是443.

我知道,如果我正在运行自己的Nginx,则可以设置重定向规则…但是,如果可能的话,我希望保留在opsworks的处理方式中.

最佳答案
我认为在OpsWorks中执行此操作的唯一方法是创建自定义配方,以修改/ etc / nginx / sites-available /#{application}.在您的自定义食谱中:

somecookbook / recipes / nginx.rb

node[:deploy].each do |application,deploy| 

      service "nginx" do
        supports :status => true
        action :nothing
      end

      # Add HTTP => HTTPS redirect      
      template "/tmp/http_redirect.conf" do
        source "nginx/http_redirect.conf.erb"
      end

      execute "redirect HTTP to HTTPS" do
        cwd "/etc/nginx/sites-available"
        command "cat #{application} /tmp/http_redirect.conf > /tmp/#{application}.conf && cat /tmp/#{application}.conf > #{application}"
        notifies :restart,"service[nginx]",:immediately
      end                                      
  end    
end

然后在配置中:

somecookbook / templates / default / nginx / http_redirect.conf.erb

server {
    listen       80;
    rewrite ^(.*) https://$host$1 permanent;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读