nginx 将http请求转到https

阅读 (1187)
nginx做301跳转,将http转到https,这样可保证以前分享出去的http域名还可以正常使用
server {
    listen 80;
    server_name domain.com;
    rewrite ^(.*) https://$server_name$1 permanent;
}
server {
    listen 443 ssl;
    server_name domain.com;
    ssl on;
    ssl_certificate     /etc/nginx/ssl/domain.com.crt;
    ssl_certificate_key /etc/nginx/ssl/domain.com.crt;
    # other
}

如果是用的阿里云的https证书策略:买的证书指向负载,负载再转发到服务器,那可以把将负载重新指向个端口,如8080,那实际https的域名是指向了服务器的8080端口,那我们再把80指向8080即可实现

server {
    listen 80;
    server_name domain.com;
    rewrite ^(.*) https://$server_name$1 permanent;
}
server {
    listen 8080;
    server_name domain.com;
   
    # other
}

 

更新于:2019-09-03 14:04:46
返回顶部