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

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

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

拦截http,301到httpsnginx

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

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

其实就是拦截全部80端口的请求,而后重定向到https的对应uriubuntu

完整配置以下:dom

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网站