配置参数如下:
ssl on | off;
listen 443 ssl;
ssl_certificate /path/to/file;
ssl_certificate_key /path/to/file;
ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];
ssl_session_cache off | none | [builtin[:size]] [shared:name:size];
off:
none:
builtin[:size]:
[shared:name:size]:
大小,一兆可以存储4000个会话信息,多个虚拟主机可以使用相同的缓存名称
ssl_session_timeout time;
[root@centos8 ~]
[root@centos8 nginx]
[root@centos8 nginx]
[root@centos8 nginx]
ca.key -x509 -days 3650 -out ca.crt
Generating a 4096 bit RSA private key
.................++
.....
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HuBei
Locality Name (eg, city) [Default City]:HuBei
Organization Name (eg, company) [Default Company Ltd]:tan
Organizational Unit Name (eg, section) []:tan
Common Name (eg, your name or your server's hostname) []:ca.tan.org #通用名称
Email Address []: qqq@qq.com#邮箱
[root@centos8 certs]# ll ca.crt
-rw-r--r-- 1 root root 2118 Feb 22 12:10 ca.crt
#自制key和csr文件
[root@centos8 certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout
www.tan.org.key -out www.tan.org.csr
Generating a 4096 bit RSA private key
........................................................................++
......
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HuBei
Locality Name (eg, city) [Default City]:HuBei
Organization Name (eg, company) [Default Company Ltd]:tan.org
Organizational Unit Name (eg, section) []:tan.org
Common Name (eg, your name or your server's hostname) []:www.tan.org
Email Address []:qqqq@qq.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@centos8 certs]
total 16
-rw-r--r-- 1 root root 2118 Feb 22 12:10 ca.crt
-rw-r--r-- 1 root root 3272 Feb 22 12:10 ca.key
-rw-r--r-- 1 root root 1760 Feb 22 12:18 www.tan.org.csr
-rw-r--r-- 1 root root 3272 Feb 22 12:18 www.tan.org.key
[root@centos8 certs]
ca.crt -CAkey ca.key -CAcreateserial -out www.tan.org.crt
[root@centos8 certs]
Certificate:
Data:
Version: 1 (0x0)
Serial Number:
bb:76:ea:fe:f4:04:ac:06
Signature Algorithm: sha256WithRSAEncryption
Issuer: C=CN, ST=HuBei, L=HuBei, O=tan, OU=tan,
CN=tan.ca/emailAddress=qqqq@qq.com
Validity
Not Before: Feb 22 06:14:03 2019 GMT
Not After : Feb 22 06:14:03 2020 GMT
Subject: C=CN, ST=HuBei, L=HuBei, O=tan.org, OU=tan.org,
CN=www.tan.org/emailAddress=qqqq@qq.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (4096 bit)
[root@centos8 certs]
server {
listen 80;
listen 443 ssl;
ssl_certificate /apps/nginx/certs/www.tan.org.pem;
ssl_certificate_key /apps/nginx/certs/www.tan.org.key;
ssl_session_cache shared:sslcache:20m;
ssl_session_timeout 10m;
root /data/nginx/html;
}
基于通信安全考虑公司网站要求全站 https,因此要求将在不影响用户请求的情况下将http请求全部自动跳转至 https,另外也可以实现部分 location 跳转
[root@centos8 ~]
server {
listen 443 ssl;
listen 80;
ssl_certificate /apps/nginx/certs/www.tan.org.crt;
ssl_certificate_key /apps/nginx/certs/www.tan.org.key;
ssl_session_cache shared:sslcache:20m;
ssl_session_timeout 10m;
server_name www.tan.org;
location / {
root /data/nginx/html/pc;
index index.html;
if ($scheme = http ){
rewrite / https://$host redirect;
}
}
location /login {
if ($scheme = http ){
rewrite / https://$host/login redirect;
}
}
}
[root@centos7 ~]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具