当前位置:首页 > 服务器技术 > nginx

【转】Nginx跳转任意Http请求到Https

网站买了证书,绿条,多霸气!

那么自然得拦截http的访问方式了。

拦截http,301到https

各种Google,最后在Nginx官网找到例子,配置很简单,如下:

            server {
        listen          *:80;
        return          301 https://www.domain.com$request_uri;
}

其实就是拦截所有80端口的请求,然后重定向到https的对应uri

完整配置如下:

            server {
        listen  
            443
             ssl;
        ssl_certificate /home/ubuntu/www.domain.com.crt;
        ssl_certificate_key /home/ubuntu/domain.com.key;


        location ~ ^/(public/|webscan_360_cn.html|do_not_delete/noc.gif) {
                root         /home/node/static;
                expires      30d;
        }



        location / {
                proxy_pass http://127.0.0.1:5000;                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}

server {
        listen          *:80;
        return          301 https://www.domain.com$request_uri;
}

 

原文地址:http://veryyoung.me/blog/2014/12/18/nginx-301-http-to-https.html

原文:http://www.cnblogs.com/jinhuazhe2013/p/5252509.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!