首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Nginx 强制跳转到HTTPS

Nginx 强制跳转到HTTPS

作者头像
老张的哲学
发布于 2022-04-11 11:41:58
发布于 2022-04-11 11:41:58
1.3K0
举报
文章被收录于专栏:NetCore 从壹开始NetCore 从壹开始

因为使用IdentityServer4,所以也配置了HTTPS安全协议。

但是如果俩个都使用的话,一是不好区分,二是没有太多的必要,

所以就想着取消掉HTTP的访问,全部转向安全协议,

使用Nginx重写转发即可轻松实现。

直接看Nginx配置吧:

代码语言:javascript
复制

    server {
        listen       80;
        server_name  ids.neters.club;
        rewrite ^(.*)$ https://$host$1 permanent;#把http的域名请求转成https

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
              root   html;
              index  index.html index.htm;
        }

    }
  server {
        listen         443 ssl;
        server_name  ids.neters.club;  #网站域名
        ssl             on;
        ssl_certificate 1_ids.neters.club_bundle.crt;  #证书公钥
        ssl_certificate_key  2_ids.neters.club.key;    #证书私钥

        #ssl_certificate ids.neters.club.crt;  
        #ssl_certificate_key ids.neters.club.rsa; 
 
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
        ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
        ssl_prefer_server_ciphers  on;

        error_page 497 https://$host$uri?$args;

        location / {
            proxy_pass http://localhost:5004;
            proxy_redirect  off;     
            proxy_set_header        Host    $http_host;     
            proxy_set_header        X-Real-IP       $remote_addr;     
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;     
            proxy_set_header   Cookie $http_cookie;
            #proxy_cookie_path
            chunked_transfer_encoding       off;
          
        }

    }
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-01-08,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档