Nginx配置多域名与SSL证书以及强制HTTP跳转HTTPS

server {
    listen       80;
    listen       [::]:80;
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;

    server_name  域名1;
    root         目录;

    ssl_certificate "xxx.crt";
    ssl_certificate_key "xxx.key";

    #跳转HTTPS
    if ($scheme = http ) {
        return 301 https://$host$request_uri;
    }

}


server {
    listen       80;
    listen       [::]:80;
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;

    server_name  域名2;
    ssl_certificate "xxx.crt";
    ssl_certificate_key "xxx.key";

    location / {
            proxy_pass http://localhost:5002;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

发表评论