https进行配置以及http跳转到https配置

时间:2023-11-18 10:40:56

https配置:


nginx配置

server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/a.pem;
ssl_certificate_key cert/a.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;


http 强制转换https


在配置文件中加入下面代码

server {

...

if ($server_port = 80){

return 301 https://$server_name$request_uri;}

if ($scheme = http){

return 301 https://$server_name$request_uri;}

....

}