Nginx HTTPS 实现、自定义 Server 名称及升级 OpenSSL(二)|学习笔记

简介: 快速学习 Nginx HTTPS 实现、自定义 Server 名称及升级 OpenSSL

开发者学堂课程【Nginx 企业级 Web 服务实战:Nginx HTTPS 实现、自定义 Server 名称及升级 OpenSSL】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/649/detail/10761


Nginx HTTPS 实现、自定义 Server 名称及升级 OpenSSL(二)

五、实现多域名 HTTPS

Nginx 支持基于单个 IP 实现多域名的功能,并且还支持单 IP 多域名的基础之上实现HTTPS,其实是基于 Nginx 的 SNI (Server Name Indication) 功能实现,SNI 是为了解决一个 Nginx 服务 器内使用一个 IP 绑定多个域名和证书的功能,其具体功能是客户端在连接到服务器建立 SS L 链接之前先发送要访问站点的域名(Hostname),这样服务器再根据这个域名返回给客户端一个合适的证书。

#制作 key 和 csr 文件

[root0s2 certs]# openssl req -newkey rsa:4096 -nodes -sha256 - keyout

mobile . magedu .net .key -out mobile . magedu .net .csr

Generating a 4096 bit RSA private key

…………

Country Name (2 letter code) [xx]:CN

State or Province Name (full name) []:BeiJing

Locality Name (eg,city) [Default City]:BeiJing

Organization Name (eg, company) [Default Company Ltd] :magedu

Organizational Unit Name (eg, section) [] :magedu

Comon Name (eg, your name or your server's hostname) []:mobile . magedu .net

Email Address [] : 2973707860@qq . com

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name [] :

#签名证书

[root0s2 certs]# openssl x509 -req -days 3650 -in mobile.magedu.net.csr -CA ca.crt

Cakey ca.ke -CAcreateserial-out mobile.magedu.net.crt

Signature oksubject=/C=CN/ST=BeiJing/L=BeiJing/0=magedu/0U=magedu/CN=obile.magedu.net/emailAddress=29737078600qq。com

Getting CA Private Key

#验证证书内容

[root@s2 certs]# openss1 x509 -in mobile . magedu.net.crt -noout -text

Certificate:

Data:

Version: 1 (0x0)

Serial Number :  

bb:76:ea:fe: f4:04:8C:07

Signature Algorithm: sha256W1 thRSAEncryption

Issuer: C=CN,ST=BeiJing, L=Beijing, 0=magedu.Ltd, ou=magedu,

CN=magedu. ca/ emailAddress-2973707860@qq. com

Validity

Not Before: Feb 22 13:50:43 2019 GMT

Not After : Feb 19 13:50:43 2029 GNT

Subject: C=CN, ST=BeiJing, L=BeiJing, 0=magedu. net, oU=magedu.net,

CN=www. magedu. net/emailAddress-2973707860@qq. com

Subject Public Key Info:

Public Key Algorithm: rsaEncryption

Public-Key: (4096 bit )

#Nginx 配置

[root@s2 certs]# cat /apps/nginx/conf/conf . d/mobile . conf

server {

listen   80;

server_ name mobile .magedu.net;

location 1 {

root   html;

index   index.html index. htm;

}

location /inux38 {

root   /data/nginx/mobile/html;

index   index.html index. htm;

}

location /python {

root   /data/nginx/mobile/html;

index   index.html index.htm;

}

}

Server {

listen 443 ssl;

server_name mobile .fagedu.net;  

ssl_certificate /apps/nginx/certs/mobile.magedu.net.crt;

ssl_certificate.key /apps/nginx/certs/mobile.magedu.net.key;

ssl_session cache shared:sslcache :20m;

ssl_ session_ tineout 100;  

location / {

root   html;

index   index.html index .htm;

}

location /linux38 {

root   /data/nginx/mobile/html;

index   index. html index.htm;

}

location /python {

root   /data/nginx/mobile/html;

index   index. html index htm;

}

六、关于 favicon.ico

favicon.ico 文件是浏览器收藏网址时显示的图标,当客户端使用浏览器问页面时,浏览器会自己主动发起请求获取页面的 favicon.co 文件,但是当浏览器请求的 favicon.ico 文件不存在时,服务器会记录404日志,而且浏览器也会显示404报错。

解决办法:

#一:服务器不记录访问日志:

#location = /favicon.ico {

#1og.not_ound off;

#access_1og off;

#}

#二:将图标保存到指定目录访问:

#location - /favicon\.icos {

location = /favicon.ico {

root   /data/nginx/html/pc/images;

expires 90d;  #设置文件过期时间

}

七、安全选项

1、隐藏 Nginx 版本号:

更改 nginx 源码信息并重新编译 Nginx

# vim src/http/ngx. http. header. filter. module.c

49 static u char ngx. http. server. string[] = "Server: 1inux38" CRLF;#定义响应报文中的 server 字段信息

▼Response Headers   view source

Connection: keep- alive

Date: Mon, 28 oct 2019 16:32:10 GMT

ETag:"5db41959-19"

Keep-Alive: timeout=65

Last-Modified: sat, 26 oct 2019 10:00:57 GMT

Server:magedu/1.2

2、升级 OpenSSL 版本:

心脏出血(英语: Heartbleed) ,也简称为心血漏洞,是一个出现在加密程序库 OpenSSL 的安全漏洞,该程序库广泛用于实现互联网的传输层安全(TLS) 协议。

它于2012年被引入了软件中,2014年4月首次向公众披露。只要使用的是存在缺陷的 OpenSSL 实例,无论是服务器还是客户端,都可能因此而受到攻击。

此问题的原因是在实现 TLS 的心跳扩展时没有对输入进行适当验证(缺少边界检查) ,因此漏洞的名称来源于“心跳”(heartbeat)。该程序错误属于缓冲区过读,即可以读取的数据比应该允许读取的还多。

准备 Openssl 源码包:

# pwd

/usr/1ocal/src

# tar xvf openss1-1.1.1d

编译安装 Nginx 并制定新版本 OpenSSL 路径:

# cd /usr/1ocal/src/nginx-1.16.1/

#./configure - -prefix=/apps/nginx --user=nginx --group=nginx --with-http. ssl module --

with-http_v2_module --with-http. realip_ module --with-http. stub_ status_ module --with-

http_gzip_static_module --with-pcre --with-stream --with-stream_ ssl. module --with-

stream_realip_module --with-select. module - -with-file-aio -- add-

module=/usr/1ocal/src/echo-nginx- module . with- openssl=/usr/1ocal/src/openss1-1.1.1d

# make && make install

验证并启动 Nginx:

# /apps/nginx/sbin/nginx -t

nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /apps/nginx/conf/nginx.conf test is successful

# /apps/nginx/sbin/nginx

相关文章
|
5月前
|
应用服务中间件 Linux 网络安全
Centos 8.0中Nginx配置文件和https正书添加配置
这是一份Nginx配置文件,包含HTTP与HTTPS服务设置。主要功能如下:1) 将HTTP(80端口)请求重定向至HTTPS(443端口),增强安全性;2) 配置SSL证书,支持TLSv1.1至TLSv1.3协议;3) 使用uWSGI与后端应用通信(如Django);4) 静态文件托管路径设为`/root/code/static/`;5) 定制错误页面(404、50x)。适用于Web应用部署场景。
666 87
|
5月前
|
网络安全 开发者
如何解决HTTPS协议在WordPress升级后对网站不兼容的问题
以上就是解决WordPress升级后HTTPS协议对网站的不兼容问题的方法。希望能把这个棘手的问题看成是学校的管理问题一样来应对,将复杂的技术问题变得更加有趣和形象,并寻觅出解决问题的方式。希望你的网站能在新的学期得到更好的发展!
134 19
|
8月前
|
应用服务中间件 Linux nginx
【Azure App Service】基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?
基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?Web App Linux 默认使用的 Nginx 版本是由平台预定义的,无法更改这个版本。
231 77
|
自然语言处理 大数据 应用服务中间件
大数据-172 Elasticsearch 索引操作 与 IK 分词器 自定义停用词 Nginx 服务
大数据-172 Elasticsearch 索引操作 与 IK 分词器 自定义停用词 Nginx 服务
236 5
|
10月前
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
3236 8
|
11月前
|
Web App开发 算法 应用服务中间件
nginx开启局域网https访问
【10月更文挑战第22天】为了调试WebRTC功能,需要在局域网内搭建HTTPS协议。具体步骤包括:在已部署Nginx和安装OpenSSL的环境中生成私钥、证书签名请求和自签名证书;将生成的文件放置到Nginx的证书目录并修改Nginx配置文件,最后重启Nginx服务。注意,自签名证书不受第三方机构认可,如需正式使用,需向CA申请签名。
560 2
|
安全 应用服务中间件 Shell
nginx配置https的ssl证书和域名
nginx配置https的ssl证书和域名
|
Docker 容器
docker nginx-proxy 添加自定义https网站
docker nginx-proxy 添加自定义https网站
141 4
|
安全 应用服务中间件 网络安全
简单比较 http https http2,我们要如何把http升级为https
【9月更文挑战第13天】本文对比了HTTP、HTTPS和HTTP/2的特点与适用场景。HTTP以明文传输,适合低安全要求的环境;HTTPS通过SSL/TLS加密,适用于电子商务等安全要求高的场景;HTTP/2采用二进制格式和多路复用,适合高性能Web应用。文章还详细介绍了将HTTP升级为HTTPS的步骤,包括申请和安装SSL证书、配置Web服务器、重定向HTTP流量到HTTPS以及测试HTTPS功能。升级到HTTPS可提高数据安全性和用户信任度。
444 13
|
安全 应用服务中间件 网络安全
修复HTTPS升级后出现 Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure frame 'http://xxx'. This request has been blocked; the content must be served over HTTPS. 的问题
修复HTTPS升级后出现 Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure frame 'http://xxx'. This request has been blocked; the content must be served over HTTPS. 的问题