nginx+wordpress安装SSL实现https访问

nginx配置文件修改支持https

将下面的内容放入/usr/local/nginx/conf/vhost/favorbook.com.conf

server {
listen 80;
server_name favorbook.com;
return 301 https://$host$request_uri;
}
server
{
listen 443 ssl;
server_name favorbook.com;
ssl_certificate /root/ssl/unified.crt;
ssl_certificate_key /root/ssl/my-private-decrypted.key;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/favorbook.com;
include wordpress.conf;
#error_page 404 /404.html;
location ~ [^/].php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 12h;
}
access_log /home/wwwlogs/favorbook.com.log access;
}

wordpress支持https跳转

参考: https://blog.shiniv.com/2014/06/open-http-and-https-in-wordpress/

其实只需要做一个步骤,把下列内容放到wp-config.php就可以了。

$site_url = (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT']) ? "https://" : "http://") . "favorbook.com";
define('WP_SITEURL', $site_url);
define('WP_HOME', $site_url);
define("WP_CONTENT_URL", $site_url . "/wp-content");
/* 强制使用SSL进行登录和后台管理 */
define('FORCE_SSL_LOGIN', false);
define('FORCE_SSL_ADMIN', true);

混合内容警告

如果在页面中同时嵌入了http协议的内容,例如一张图片,则浏览器地址栏将不是一把绿色的锁。最简单的解决办法是把数据库里所有的http都替换为https的,装上 Search and Replace 这个插件,轻松搞定。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: