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. Android多线程之(一)——View.post()篇

    前言 提起View.post(),相信不少童鞋一点都不陌生,它用得最多的有两个功能,使用简便而且实用: 1)在子线程中更新UI.从子线程中切换到主线程更新UI,不需要额外new一个Handler实例来 ...

  2. GitHub 上值得参考的完整的 iOS-App 源码

    转自:https://www.zhihu.com/question/28518265 作者:wjh2005链接:https://www.zhihu.com/question/28518265/answ ...

  3. h5-面试题

    干货!各种常见布局实现+知名网站实例分析 前端面试考点多?看这些文章就够了(2019年6月更新版) 前端面试:这50个经典前端面试题面试者必看! Vue面试中,经常会被问到的面试题/Vue知识点整理 ...

  4. golang包管理的古往今来

    https://golang.org/ before GO1.5-GOPATH 在GO1.5之前用GOPATH以及GOROOT这两个环境变量来决定包的位置. GOROOT就是告知当前go的安装位置,编 ...

  5. Binary Search Tree analog

    Description Binary Search Tree, abbreviated as BST, is a kind of binary tree maintains the following ...

  6. LightOj-1030 Discovering Gold (期望DP)

    You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave c ...

  7. HDU3870- intervals(差分约束)

    You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...

  8. eviews面板数据的操作

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

  9. B.Silly Mistake

    题目:愚蠢的错误 题意:中心公司有一个办公室有一个成熟的安全系统,这里面有10^6个雇员,编号从1到10^6 安全系统有入口和出口,数字i表示第i个雇员进入,-i表示第i个雇员出去 公司有一些严格的规 ...

  10. [Java并发] AQS抽象队列同步器源码解析--锁获取过程

    要深入了解java并发知识,AbstractQueuedSynchronizer(AQS)是必须要拿出来深入学习的,AQS可以说是贯穿了整个JUC并发包,例如ReentrantLock,CountDo ...