Nginx 配置Https 协议

Stella981
• 阅读 760

1. 去阿里云SSL证书购买证书

Nginx 配置Https 协议

 2.  审核通过后下载nginx 的ssl证书

Nginx 配置Https 协议

3. 解压出来两个文件 xxx.pem, xxx.key 

4. 在服务器 nginx安装目录(一般/usr/local/nginx/conf)下创建目录cert,并将两个文件上传至此目录下

5.修改Nginx安装目录/conf/nginx.conf文件

# HTTPS server
  server {
  listen 443;
  server_name localhost; ssl on; ssl_certificate cert.pem; ssl_certificate_key cert.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; location / { 


# 以下属性中以ssl开头的属性代表与证书配置有关,其他属性请根据自己的需要进行配置。
server {
listen 443 ssl;   #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
server_name localhost;  #将localhost修改为您证书绑定的域名,例如:www.example.com。
root html;
index index.html index.htm;
ssl_certificate cert/domain name.pem;   #将domain name.pem替换成您证书的文件名。
ssl_certificate_key cert/domain name.key;   #将domain name.key替换成您证书的密钥文件名。
ssl_session_timeout 5m;
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;   
}
}                     

6.保存nginx.conf文件

7.重启nginx

$ systemctl stop nginx.service

$ systemctl start nginx.service

8.开启nginx SSL模块

Nginx如果未开启SSL模块,配置Https时提示如下错误:

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf

解释:nginx缺少http_ssl_module模块,需要在已安装的nginx中添加ssl模块。

说明:我的nginx安装目录为:/usr/local/nginx , 源码包在/usr/src/nginx-1.5.9目录

Nginx开启SSL模块:

切换到源码包:

cd /usr/src/nginx-1.5.9

查看nginx原有的模块

/usr/local/nginx/sbin/nginx -V

 在configure arguments:后面显示的原有的configure参数如下:

--prefix=/usr/local/nginx --with-http_stub_status_module

 9. 从新配置SSL模块

进入nginx源码包目录,运行:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

配置完成后,运行命令make命令:

make

注意:此处不能进行make install,否则就是覆盖安装

10:替换已安装好的nginx包
替换之前先备份:

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

先停止nginx服务:

Nginx 配置Https 协议

//查询nginx主进程号
$ ps -ef | grep nginx

//从容停止Nginx:
$kill -QUIT 主进程号

//快速停止Nginx:
kill -TERM 主进程号

//强制停止Nginx:
pkill -9 nginx

Nginx 配置Https 协议

将刚刚编译好的nginx覆盖掉原有的nginx

cp ./objs/nginx /usr/local/nginx/sbin/

然后启动nginx,仍可以通过命令查看是否已经加入成功

/usr/local/nginx/sbin/nginx -V

此时应该显示为即配置成功:

configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

补充:

nginx配置ssl,支持https的配置:

Nginx 配置Https 协议

server {
        listen       443 ssl;
        server_name  aa.abc.com;

        ssl_certificate      cert/2643408_xxx.pem;
        ssl_certificate_key  cert/2643408_xxx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            proxy_pass http://127.0.0.1:8886;
        }
    }

nginx http 跳转 https:

Nginx 配置Https 协议

server {
        listen       80;
        server_name  aa.abc.com;

      rewrite ^(.*)$ https://$host$1 permanent;# 把http的域名请求转成https

}

11. 在阿里控制台开启443安全组

安全组-》配置规则-》添加安全组规则

12. 开启防火墙443端口,开启https

// 开启http

firewall-cmd --permanent --zone=public --add-service=http  

// 开启https

firewall-cmd --permanent --zone=public --add-service=https

// 开启80 和 443 端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=443/tcp --permanent

// 重启防护墙

firewall-cmd --reload

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
2年前
Nginx配置https
一、开启nginx的ssl模块1.未安装过nginx,编译安装配置参数如下:./configure\prefix/usr/local/nginx\withpcre\withhttp\_ssl\_modulessl模块\withhttp\_stub\_status\_module\wit
Stella981 Stella981
2年前
List的Select 和Select().tolist()
List<PersondelpnewList<Person{newPerson{Id1,Name"小明1",Age11,Sign0},newPerson{Id2,Name"小明2",Age12,
Wesley13 Wesley13
2年前
MySQL8开启ssl加密
1概述MySQL从5.7开始默认开启SSL加密功能,进入MySQL控制台后输入status可以查看ssl的状态,出现下图表示在使用ssl:!在这里插入图片描述(https://imgblog.csdnimg.cn/20200325131703934.png)另外,ssl加密需要密钥与证书,可以使用openssl手动生成或使用my
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Hacker News 简讯 2020
!(https://oscimg.oschina.net/oscnet/up3b137e2e6620f7a63f11a96485b1fb3b.png)最后更新时间:2020082623:00
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这