您的位置:首页 > 理论基础 > 计算机网络

阿里云SLB配置http跳转https

2017-09-18 19:07 826 查看
1、在ECS中安装Nginx,可以参考我的另一篇文章Linux安装Nginx

2、 nginx配置server参考

server {

listen 80;

server_name xx.domain.com xx.domain.com;

rewrite ^/(.*)https://xx.domain.com/1 permanent;

# access_log  logs/hiracer.com.80.log  access;
}


3、阿里云SLB https配置参考



4、配置思路:

这样用户访问的流程是这样的:

1.如果是 https 的请求直接由 443 端口转到后端我的真实网站 8080 端口获取内容,SSL 数据加密的任务交给 SLB 处理。

2.如果是 http 的请求从SLB的 80 端口转至后端的 80 端口,由 Apache 重写成 https URL,转至 SLB 的 443 端口,对应流程1。

这样不管用户用 http还是 https 最终的请求都是 https 的请求。

5、ngnix 如此配置之后,实际遇到了一个问题,就是以接口形式post请过来,强制跳转之后会变成GET请求,同时请求数据会丢失,因此,我对请求路径做了不同处理

页面请求强制跳转https

接口请求不做强制跳转,只做代理

server {

listen 80;

server_name xx.domain.com xx.domain.com;

location = / {

rewrite ^/(.*)https://xx.domain.com/1 permanent;

}

location ^~ /h5/ {

rewrite ^/(.*)https://xx.domain.com/1 permanent;

}

location ^~ /admin/ {

rewrite ^/(.*)https://xx.domain.com/1 permanent;

}

location / {

proxy_pass http://localhost:8080;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 阿里云