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

设置Elastic Load balancer后,我的https不再起作用了. Nginx错误

发布时间:2020-12-13 21:20:07 所属栏目:Nginx 来源:网络整理
导读:我有一个常规实例,当不在负载均衡器后面时工作正常. 我设置了一个ELB,其中80转发到80和443转发到443和粘性会话. 之后,我转到任何https页面时都会收到此错误. The plain HTTP request was sent to HTTPS port 我处理在我的nginx配置中的某些页面上强制https的

我有一个常规实例,当不在负载均衡器后面时工作正常.
我设置了一个ELB,其中80转发到80和443转发到443和粘性会话.
之后,我转到任何https页面时都会收到此错误.

The plain HTTP request was sent to HTTPS port

我处理在我的nginx配置中的某些页面上强制https的过程.
为了让这个工作,我需要做什么?我在下面输入我的nginx配置的准系统版本.

http {

  include               mime.types;
  default_type          application/octet-stream;

  # Directories
  client_body_temp_path tmp/client_body/  2 2;
  fastcgi_temp_path     tmp/fastcgi/;
  proxy_temp_path       tmp/proxy/;
  uwsgi_temp_path       tmp/uwsgi/;

  server {
    listen              443;
    ssl                 on;
    ssl_certificate     ssl.crt;
    ssl_certificate_key ssl.key;

    server_name www.shirtsby.me;
    if ($host ~* ^www.(.*)) {
        set $host_without_www $1;
        rewrite ^/(.*) $scheme://$host_without_www/$1 permanent;
    }

    location ~ ^/(images|img|thumbs|js|css)/  {
          root /app/public;
    }
    if ($uri ~ ^/(images|img|thumbs|js|css)/) {
        set $ssltoggle 1;
    }
    if ($uri ~ "/nonsecure") {
        set $ssltoggle 1;
    }
    if ($ssltoggle != 1) {
        rewrite ^(.*)$http://$server_name$1 permanent;
    }

    location / {
      uwsgi_pass  unix:/site/sock/uwsgi.sock;
      include     uwsgi_params;
    }

  }

  server {
    listen      80;
    server_name www.shirtsby.me;
    if ($host ~* ^www.(.*)) {
        set $host_without_www $1;
        rewrite ^/(.*) $scheme://$host_without_www/$1 permanent;
    }

    if ($uri ~ "/secure") {
        set $ssltoggle 1;
    }
    if ($ssltoggle = 1) {
        rewrite ^(.*)$https://$server_name$1 permanent;
    }

    location ~ ^/(images|img|thumbs|js|css)/  {
          root /app/public;
    }

    location / {
      uwsgi_pass  unix:/home/ubuntu/site/sock/uwsgi.sock;
      include     uwsgi_params;
    }
  }
}
最佳答案
结束了在nginx IRC频道中获得vandemar的答案.
看起来很简单,但我努力搞清楚. ELB正在处理SSL,我已经给了它所有的证书信息.问题是尝试在单个实例或配置文件中再次处理它.
解决方案是从配置文件中删除所有SSL内容.
所以删除这三行修复了一切:

ssl                 on;
ssl_certificate     ssl.crt;
ssl_certificate_key ssl.key;

(编辑:李大同)

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

    推荐文章
      热点阅读