server {
    listen 80;
    server_name www.域名.com;
    rewrite ^(.*)$ https://${server_name}$1 permanent; 
}
server {
    listen 443;
    server_name www.域名.com;
    root /home/wwwroot;
    ssl on;
    ssl_certificate /etc/nginx/certs/server.crt;
    ssl_certificate_key /etc/nginx/certs/server.key;
    ....
}

备注: ${server_name}可以换成$host

重启服务:

sudo systemctl restart nginx

转载:https://blog.csdn.net/m0_37886429/article/details/72271983

posted on 2020-08-06 14:16  你不知道的浪漫  阅读(2721)  评论(0编辑  收藏  举报