1、http升级到https

1.1、检查 Nginx 是否支持 SSL

/usr/local/nginx/sbin/nginx  -V
configure arguments中是否有--with-http_ssl_module
如:
nginx version: nginx/1.13.
built by gcc 4.8. (Red Hat 4.8.-) (GCC)
built with OpenSSL 1.0.2k-fips Jan
TLS SNI support enabled
configure arguments: --with-http_ssl_module

1.2、为nginx添加SSL 模块

)进入nginx安装目录执行:
./configure --with-http_ssl_module
然后,注意不要make install
make
)备份原 Nginx 执行脚本
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
)将新版本 Nginx 编译脚本放到可执行文件目录下
cd objs/ cp nginx /usr/local/nginx/sbin/
)进行平滑升级
make upgrade
再次检查是否安装成功:
/usr/local/nginx/sbin/nginx -V

1.3、修改nginx配置

cd /usr/local/nginx/conf
vim nginx.conf 
server{
listen ;
listen ssl;
ssl on;
ssl_certificate /etc/nginx/nginx.nopasswd.crt; ##证书.crt
ssl_certificate_key /etc/nginx/nginx.nopasswd.key; ##证书.key
server_name ****;
error_page /50x.html;
location = /50x.html {
root html;
}
location / {
try_files $uri $uri/ /index.html;
root /var/www/test;
index index.html index.htm;
}
location ~ /api/(.*)$ {
proxy_pass http://****/$1?$query_string;
proxy_set_header Host $http_host;
proxy_set_header X-Forward-For $remote_addr;
} }

注意:https需要SSL证书,可以到阿里云或腾讯云申请免费版,有效期一年

2、同时支持http和https两种请求

server{
listen ;
listen ssl;
# ssl on;
ssl_certificate /etc/nginx/nginx.nopasswd.crt;
ssl_certificate_key /etc/nginx/nginx.nopasswd.key;
......

将ssl on;注释就可以了,其中http访问88端口,而https访问443端口(http默认80端口,https默认443端口)

3、http自动转向https

nginx配置新增server的配置

 server {
listen ;
server_name 你的域名;
rewrite ^(.*)$ https://$host$1 permanent;
}

nginx将http升级到https并且同时支持http和https两种请求、http自动转向https的更多相关文章

  1. 【Nginx】将http升级到https并且同时支持http和https两种请求

    一.如何将http升级到https 需要满足下面三个: 1.域名 2.nginx 3.SSL证书     一般第三方证书颁发机构下发的证书是收费的,一年好几千.    1) 从腾讯云申请免费的SSL证 ...

  2. Nginx 反向代理(http转htpps,并支持80端口继续提交post请求)

    项目是一个web server + 多个client的形式,client由用户安装在自己的电脑上 由http升级为https后,我们通过在Nginx做了80端口重定向443的配置,使用户通过访问htt ...

  3. JGit与远程仓库链接使用的两种验证方式(ssh和https)

    JGit是使用JAVA的API来操控Git仓库的库,由Eclipse公司维护.他提供的API分成两个层次,底层命令和高层命令.底层API是直接作用于低级的仓库对象,高层的API是一个面向普通用户级别功 ...

  4. 十一.spring-boot 添加http自动转向https

    SSL是为网络通信提供安全以及保证数据完整性的的一种安全协议,SSL在网络传输层对网络连接进行加密. 例:cas 的单点登陆就用到了SSL 一.安全证书的生成 1.可以使用jdk自带的证书生成工具,j ...

  5. nginx开启ssl并把http重定向到https的两种方式

    1 简介 Nginx是一个非常强大和流行的高性能Web服务器.本文讲解Nginx如何整合https并将http重定向到https. https相关文章如下: (1)Springboot整合https原 ...

  6. Chrome禁止http自动转为https

    解决方法 在Chrome浏览器地址栏输入chrome://net-internals/#hsts 在Delete domain security policies 中输入要删除自动转换的域名 原因 将 ...

  7. nginx 和 tp兼容pathinfo和rewrite两种url访问方式

    环境:centos7,yum安装的nginx1.10.php-fpm,tp3.2 本方法只需要配置nginx.conf的一个文件就可以支持pathinfo和rewrite两种url访问方式 vim / ...

  8. nginx、TP框架实现兼容pathinfo和rewrite两种url访问方式

    环境:centos7,yum安装的nginx1.10.php-fpm,tp3.2 本方法只需要配置nginx.conf的一个文件就可以支持pathinfo和rewrite两种url访问方式 vim / ...

  9. 源码安装nginx以及平滑升级

                                                           源码安装nginx以及平滑升级                               ...

随机推荐

  1. nginx、redis在Centos7中,加入开机自启动

    nginx加入开机启动 cat <<EOF >> /etc/systemd/system/nginx.service> [Unit]> Description=ng ...

  2. 【nodejs原理&源码赏析(6)】深度剖析cluster模块源码与node.js多进程(下)

    [摘要] cluster模块详解 示例代码托管在:http://www.github.com/dashnowords/blogs 阅读本章需要先阅读本系列前两章内容预热一下. 一. 引言 前两篇博文中 ...

  3. 【nodejs原理&源码赏析(3)】欣赏手术级的原型链加工艺术

    [摘要] 学习经典代码中的prototype加工 示例代码托管在:http://www.github.com/dashnowords/blogs 好的代码都差不多,烂的代码却各有各的烂法. 一. 概述 ...

  4. 失去循环标签的Python,我这样实现跳出外层循环

    不完美的Python 自从各类Python大火,感觉天上地下哪儿都有Python的一席之地,Python功夫好啊-但python有些细节上缺少其他语言的便利.今天我们就来举几个例子. 跳出外层循环 大 ...

  5. windows下利用iis建立网站网站并实现局域共享

    博客园 首页 新随笔 联系 管理 订阅 随笔- 54  文章- 9  评论- 0  Windows下利用IIS建立网站并实现局域网共享 https://blog.csdn.net/qq_4148541 ...

  6. iOS 音频开发之CoreAudio

    转自:http://www.cnblogs.com/javawebsoa/archive/2013/05/20/3089511.html 接 触过IOS音频开发的同学都知道,Core Audio 是I ...

  7. flink基本原理

    一.简介 开源流式处理系统在不断地发展,从一开始只关注低延迟指标到现在兼顾延迟.吞吐与结果准确性,在发展过程中解决了很多问题,编程API的易用性也在不断地提高.本文介绍一下 Flink 中的核心概念, ...

  8. POJ 2559 Langest Rectangle in a Histogame

    A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rec ...

  9. Linux中sed基础

    sed是一种流编辑器,它是文本处理中非常重要的工具,能够完美的配合正则表达式使用,功能不同凡响.处理时,把当前处理的行存储在临时缓冲区中,称为"模式空间"(pattern spac ...

  10. eviews面板数据的操作

    数据结构: 打开eviews File>new>workfile Object>new object > pool 输入城市名称: _bj 下划线加名称(必须是英文),竖着输入 ...