生成证书
参考《SSL证书生成》,生成适合于自己的免费证书。也可购买商业SSL证书。
如果只想生成CSR,用CSR在CA机构换取CRT证书,可以执行下面命令即可:
1
| openssl req -new -nodes -newkey rsa:2048 -keyout server.key -out server.csr
|
配置Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| server { listen 80; server_name www.abc.zyx; rewrite ^(.*)$ https://$host$1 permanent; }
server { listen 443 ssl; server_name www.abc.zyx; charset utf-8; ssl_certificate ssl/server.crt; ssl_certificate_key ssl/server.key; ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:CAMELLIA256-SHA:CAMELLIA128-SHA256"; ssl_session_cache shared:SSL:20m; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on;
location / { root /var/www/html/abc; index index.html index.htm index.php; if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } rewrite /wp-admin$ $scheme://$host$uri/ permanent; try_files $uri $uri/ /index.php?$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; }
location ~ \.php$ { root /var/www/html/abc; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include fastcgi.conf; try_files $uri =404; }
location ~ /\.ht { deny all; } }
|
注意:ssl_protocols配置项,不添加TLSv1会导致部分IE浏览器打不开,如果加上TLSv1用站长工具检测会提示PCI DSS 不合规。
重新加载配置文件:nginx -s reload
。
如果是阿里云ECS服务器,需要在控制台的安全组中增加入网的443端口,具体配置可以参照其他的配置。
如果这时候https还不能访问,则需要查看Ubuntu服务器是否开启了443端口,如果无,则需要开启。
查看443端口是否开启:
1
| iptables -L -n | grep 443
|
开启443端口,并让其生效:
1 2
| iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT iptables-save
|
WordPress后台改成https访问
主题支持改动
如果主题中有修改网站URL的入口,则直接在admin管理后台修改即可。
如果使用的 WP Editor.md
插件,也需要修改思维导图库资源路径,一般情况下可以使用//
替换http://
,这样资源就可以根据站点的scheme自动切换了。
SQL UPDATE
1 2 3 4 5 6 7
| update scat_posts set post_content = replace(post_content, 'http://www.abc.xyz', '//www.abc.xyz') where post_content like '%http://www.abc.xyz%';
update scat_posts set guid = replace(guid, 'http://www.abc.xyz', 'https://www.abc.xyz') where guid like '%http://www.abc.xyz%';
|
通过找到当前主题下的 function.php 文件
1 2 3 4 5 6 7
| function replacehttp($content){ if( is_ssl() ){ $content = str_replace('http://www.abc.xyz', 'http://www.abc.xyz', $content); } return $content; } add_filter('the_content', 'replacehttp');
|
wp-config.php文件中添加
1 2
| define('FORCE_SSL_ADMIN', true); define('FORCE_SSL_LOGIN', true);
|