WordPress由http转为https
原来博客是http访问的,这次换了vps,装lnmp时发现默认添加了https的支持,所以干脆使用https吧.
lnmp ssl add
然后按照提示配置即可
vi /usr/local/nginx/conf/vhost/www.bicner.com.conf
在80端口的接听中加一个重定向
server{
listen 80;
server_name www.bicner.com;
rewrite ^(.*) https://$server_name$1 permanent;
……..就是加了上面那一行
lnmp restart 重启一下让配置生效
然后是去后台将博客的链接由http改为https
这样网站就可以https访问了,但是图片的连接还是http的,
在主题function.php的最后添加一个替换函数即可.
/* 替换图片链接为 https */ function https_image_replacer($content){ if( is_ssl() ){ $host_name = $_SERVER['HTTP_HOST']; $http_host_name='http://'.$host_name.'/wp-content/uploads'; $https_host_name='https://'.$host_name.'/wp-content/uploads'; $content = str_replace($http_host_name, $https_host_name, $content); } return $content; } add_filter('the_content', 'https_image_replacer');
本文出自 纳百川,转载时请注明出处及相应链接。
本文永久链接: https://www.bicner.com/1020.html
2条评论
这样就可以了吗?
学习了 谢谢