Nginx跳转任意Http请求到Https
原文链接 http://veryyoung.me/blog/2014/12/18/nginx-301-http-to-https.html
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。
网站买了证书,绿条,多霸气!
那么自然得拦截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;
}