跳转方式有两种

1、rewrite 方式

rewrite ^(.*) https://$server_name$1 permanent;

2、return方式

return 301 https://$server_name$request_uri;

两种方式都是添加在默认监听端口中,比如80端口下方,当访问到80端口则被重定向到https中


配置如下:

worker_processes  1;error_log  logs/error.log info;events {worker_connections  1024;
}http {include       mime.types;#log_format  main  '$remote_addr - $remote_user [$time_local] $request '  #                  '"$status" $body_bytes_sent "$http_referer" '  #                  '"$http_user_agent" "$http_x_forwarded_for"';  keepalive_timeout  1000;    proxy_read_timeout 1200;  gzip  on;  gzip_min_length  1024;  gzip_buffers     4 8k;  gzip_types       text/* application/javascript application/x-javascript text/css text/plain;  gzip_http_version 1.0;  gzip_comp_level  9;  gzip_proxied     any;  gzip_vary        on;  #output_buffers   1 32k;  #postpone_output  1460;  client_header_timeout   2048m;  client_body_timeout     2048m;  send_timeout            2048m;  sendfile                on;  tcp_nopush              on;  tcp_nodelay             off;  client_header_buffer_size 256k;  large_client_header_buffers 2 256k;  server_names_hash_bucket_size 256;  charset UTF-8;  client_max_body_size 2048M;upstream local_host {    server 127.0.0.1:8080 weight=1;}  server {listen       80;server_name  XXXX;#charset koi8-r;#rewrite ^(.*) https://$server_name$1 permanent;return 301 https://$server_name$request_uri;#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# HTTPS server#server {listen       443 ssl;server_name  XXXX;ssl_certificate     XXX.pem;ssl_certificate_key  XXXXX.key;ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;# ssl_ciphers  HIGH:!aNULL:!MD5;ssl_ciphers  ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers  on;location / {root   html;index  index.html index.htm;}location /xx {proxy_pass http://local_host;proxy_redirect          off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Real-PORT $remote_port;proxy_set_header X-Forwarded-For $scheme;proxy_set_header X-Forwarded-Ssl on;}}
}

在配置好后,正常浏览器访问可以正常跳转https,但是出现页面调用后台接口还是默认http的时候还是会报

最后通过添加header 头信息解决了,最后做个记录。

proxy_set_header X-Forwarded-Ssl on;

nginx http强制跳转https 配置相关信息相关推荐

  1. Nginx配置http301强制跳转https

    Nginx配置http301强制跳转https http强制跳转到https 在nginx配置文件内添加: if ($scheme = http) {return 301 https://$serve ...

  2. nginx设置http强制跳转https

    本文来说下nginx设置http强制跳转https 文章目录 概述 概述

  3. 解决:ngxin做http强制跳转https,接口的POST请求变成GET

    解决:ngxin做http强制跳转https,接口的POST请求变成GET 域名配置了http强制跳转htpps后发现app发起post请求会出现405错误. 所以怀疑是http强制跳转https出现 ...

  4. 开启HSTS让浏览器强制跳转HTTPS访问

    开启HSTS让浏览器强制跳转HTTPS访问 来源 https://www.cnblogs.com/luckcs/articles/6944535.html 在网站全站HTTPS后,如果用户手动敲入网站 ...

  5. 新功能:阿里云负载均衡SLB支持HTTP访问强制跳转HTTPS

    摘要: 很高兴的告诉大家,阿里云负载均衡SLB已经在澳大利亚(悉尼).日本(东京).阿联酋(迪拜).美国 (弗吉尼亚).美国(硅谷).马来西亚(吉隆坡).德国(法兰克福).新加坡.印度尼西亚(雅加达) ...

  6. Chrome谷歌浏览器 强制跳转https解决方案

    Chrome谷歌浏览器 强制跳转https解决方案 参考文章: (1)Chrome谷歌浏览器 强制跳转https解决方案 (2)https://www.cnblogs.com/dreamfine/p/ ...

  7. 计算机的相关配置信息,win7系统查看电脑配置相关信息的方案介绍

    win7系统使用久了,好多网友反馈说win7系统查看电脑配置相关信息的问题,非常不方便.有什么办法可以永久解决win7系统查看电脑配置相关信息的问题,面对win7系统查看电脑配置相关信息的图文步骤非常 ...

  8. nginx+tomcat,http强制跳转https后的error_page配置!【原创】

    最近在生产环境搭建时发现http强制301跳转到https后error_page的设置怎么都不生效,后来检查出了原因,根据网上的搜索资料在加上自己的逻辑分析,最终实现了这个功能.如有更简单的方法请高手 ...

  9. Tomcat配置8080强制跳转https端口变成8443或者80跳转443

    Tomcat配置强制https端口变成8443 跳转端口: http默认端口 8080 https默认端口 8443 或者 http默认端口 80 https默认端口 443 这里只讲tomcat配置 ...

最新文章

  1. cmake 编译文件 CMakeLists.txt 语法介绍与实例演练
  2. css样式表实验报告,css基本样式(二)
  3. Kotlin实战指南十四:协程启动模式
  4. OpenCV处理引起光学错觉的图像
  5. 如何使用Redis做MySQL的缓存
  6. python中popen的用法_python中的subprocess.Popen()使用
  7. 计算长方体体积编程_如何求N个球体在空间中所占的体积?
  8. 2003基于栈的回文字符序列判断(C++)
  9. 【Objective-C】探索Category底层的实质
  10. linux mysql5.5.50_linux下安装mysql5.5
  11. 32位x86处理器操作模式和寄存器简介
  12. Intel Optane P4800X评测(序):不用缓存和电容保护的SSD?
  13. 博客V7之后,喜庆排名进入2000之内
  14. 我的linux学习之路---配置VNC服务器(1)
  15. Redis下载部署并加入idea应用(详细笔记)
  16. 上海始终未出现真正“富人区”
  17. java forward怎么用_【后端开发】java中forward是什么
  18. mac php 单元测试,PHPUnit单元测试
  19. 80后的罗敏已经在创业路上走了十几年
  20. 2021CCPC女生专场

热门文章

  1. 微信视频号推出“创作者流量包”
  2. 拿到腾讯 offer 的第二天,我从字节跳动离职了
  3. 六家共享单车加入免押计划 押金模式即将崩盘?
  4. uploadify--上传文件控件
  5. 打开微信开发者工具后无法显示文件的问题解决方案
  6. 中学计算机课教具,中学教师20余载自制教具 “变废为宝”让课堂易懂
  7. python导入库关键词_怎么样导入RobotFramework 自定义关键字(库文件)
  8. shell编程-数组的使用
  9. 运用京东云代码托管、云编译、云部署等产品进行蓝绿部署简单实践
  10. 朋友圈文案_隐私条款