首先监听 443端口,进行ssl解析
server {
listen 443;
server_name 你网站的域名;
ssl on;
index index.html index.htm;
ssl_certificate cert/你的证书文件名.pem;
ssl_certificate_key cert/你的证书文件名.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
# nginx配置跨域
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
# 将请求转发到服务上面
proxy_pass http://tale_blog;
}
}
http 自动跳转 https
server {
listen 80;
server_name geek45.com;
location / {
root /srv/www/http.geek45.com/;
}
error_page 404 https://geek45.com/;
}
网站显示非完全安全
打开network,站内应该还有http去加载的资源,修改项目,将所有的http加载的资源,修改为https去加载即可。
http 自动跳转https 的其他方式
index.html
<html>
<meta http-equiv="refresh" content="0;url=https://test.com/">
</html>
该做法是百度的做法,不会消耗服务器资源。推荐这两种方式!