diff --git "a/23 \345\217\262\345\255\246\346\226\260/20240605 SSL\351\205\215\347\275\256.md" "b/23 \345\217\262\345\255\246\346\226\260/20240605 SSL\351\205\215\347\275\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..1e9e1992f99f67088f0c5b31e0f7eb96e1b92978 --- /dev/null +++ "b/23 \345\217\262\345\255\246\346\226\260/20240605 SSL\351\205\215\347\275\256.md" @@ -0,0 +1,54 @@ +1. ```shell + server { + #HTTPS的默认访问端口443。 + #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。 + listen 443 ssl; + + #填写证书绑定的域名 + server_name shiss04.cn; + + #填写证书文件绝对路径 + ssl_certificate cert/shiss04.pem; + #填写证书私钥文件绝对路径 + ssl_certificate_key cert/shiss04.key; + + ssl_session_cache shared:SSL:1m; + ssl_session_timeout 5m; + + #自定义设置使用的TLS协议的类型以及加密套件(以下为配置示例,请您自行评估是否需要配置) + #TLS协议版本越高,HTTPS通信的安全性越高,但是相较于低版本TLS协议,高版本TLS协议对浏览器的兼容性较差。 + ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; + ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; + + #表示优先使用服务端加密套件。默认开启 + ssl_prefer_server_ciphers on; + + + location / { + root html; + index index.html index.htm; + } + } + ``` + +2. **可选:**设置HTTP请求自动跳转HTTPS。 + + 如果您希望所有的HTTP访问自动跳转到HTTPS页面,可通过rewrite指令重定向到HTTPS。 + + **重要** + + 以下代码片段需要放置在nginx.conf文件中`server {}`代码段后面,即设置HTTP请求自动跳转HTTPS后,nginx.conf文件中会存在两个`server {}`代码段。 + + + + ```shell + server { + listen 80; + #填写证书绑定的域名 + server_name shiss04.cn; + #将所有HTTP请求通过rewrite指令重定向到HTTPS。 + rewrite ^(.*)$ https://$host$1; + location / { + index index.html index.htm; + } + } \ No newline at end of file