wordpress/nginx安全设置

栏目: 服务器 · Nginx · 发布时间: 4年前

内容简介:最近闲时研究了下博客的安全,除去系统的安全问题,主要关注点在登录这一块。我选择了这个真正能保证wp安全的这个插件,这个插件提供双重安全验证登录,跟谷歌帐户的“两步验证”是一样的原理。在wp上安装好这个插件并启用后,进入“用户”-》“我的个人资料”会看到如下界面:

最近闲时研究了下博客的安全,除去系统的安全问题,主要关注点在登录这一块。

一、安装wordpress插件实现安全登录

Google Authenticator (使用谷歌两步验证加强 WordPress 登录安全)

我选择了这个真正能保证wp安全的这个插件,这个插件提供双重安全验证登录,跟谷歌帐户的“两步验证”是一样的原理。在wp上安装好这个插件并启用后,进入“用户”-》“我的个人资料”会看到如下界面:

wordpress/nginx安全设置

选中“Active”,填写“站点描述”,保存。然后根据自己的手持设备 安装 Google 身份验证器 (我在我的apple设备及黑莓设备上都安装了),添加令牌(填写站点描述及密钥)后就绑定了。然后就可以在登录界面( 亲,切记在手持设备上绑定后再登出啊 )看到如下情况了:

wordpress/nginx安全设置

如果博客不只一个用户,其它用户也可以在他自己的资料里面启用这种两步验证的登录方式,如果用户没有启用,那么登录的时候不用填写“google authenticator code”。

当然了,通过搜索还有其它登录安全的插件,如 One Time Password (采用一次性密码登录你的 WordPress,应该类似于银行纸质的那种刮刮卡)、 WP Login Security (根据登录用户IP地址来保护你的 WordPress 安全)、 Login Lockdown (锁定无效登录)、 WP Firewall 2

二、设置SSL登录及SSL后台

HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容请看SSL。

它是一个URI scheme(抽象标识符体系),句法类同http:体系。用于安全的HTTP数据传输。https:URL表明它使用了HTTP,但HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司进行,提供了身份验证与加密通讯方法,现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。

首先要在wordpress中设置强制SSL登录及SSL后台,具体做法是:

在wordpress的根目录中找到“wp-config.php”,编辑这个文件在

wordpress/nginx安全设置

设置两个常量“FORCE_SSL_LOGIN”、“FORCE_SSL_ADMIN”为true(一定要在图中蓝色文字前设置,听说这样才能生效)。

我用得是nginx反向代理,只有如上设置肯定是不行的。

要做下面的操作前,首先要保证安装nginx的时候安装了ssl的支持,通过命令“nginx -V”就能查看你在编译的时候添加没有添加“-with-http_ssl_module”这个参数。如果没加,重新编译安装一次吧(记得备份配置文件)。

nginx准备好后就开始设置了,我在这里就不说收费的受浏览器信任的证书了,我用了“自颁发不受浏览器信任的证书”。

输入以下命令:

openssl req -new -x509 -days 365 -newkey rsa:2048  -nodes -out nginx.pem -keyout nginx.key

会生成两个文件,当然也会让你填很多问题,

Generating a 1024 bit RSA private key
...................................++++++
..............................++++++
writing new private key to 'nginx.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New Jersey
Locality Name (eg, city) []:Absecon
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SoftwareDev, LLC
Organizational Unit Name (eg, section) []:Web Services
Common Name (eg, YOUR name) []:squire.ducklington.org
Email Address []:squire@ducklington.org

“Common Name”一定要是你的域名 ,然后在nginx.conf中设置:

server {
        listen       443;
        server_name  yourdomain;
 
        ssl                  on;
        ssl_certificate      nginx.pem;
        ssl_certificate_key  nginx.key;
 
        ssl_session_timeout  5m;
 
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;
 
        add_header      Front-End-Https on;
        root /xxx;
 
        location / {
                rewrite ^ http://$host$request_uri permanent;
        }
        location /wp-admin {
                fastcgi_pass unix:/tmp/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
        location ~.*\.(php|php5)?$ {
                fastcgi_pass unix:/tmp/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
}
#下面是80端口vhost中的
rewrite ^/wp-login.php(.*) https://$host/wp-login.php$1 permanent;
location ~ ^/(wp-admin)/* {
        rewrite ^/(.*) https://$host/$1 permanent;
}

然后重新加载nginx应该就可以ssl登录了。

当然了,我遇到个问题,就是https获取css文件,返回的MIME类型为text/html。如下:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://blog.ueder.info/wp-admin/css/wp-admin.css?ver=3.4.1". 
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://blog.ueder.info/wp-admin/css/colors-fresh.css?ver=3.4.1".

出错原因在于:上面的conf文件中location /wp-admin,将所有请求都传给fastcgi_pass处理了,php cgi中始终返回text/html,所以修改conf文件后,css、js文件nginx来处理就解决问题了。

server {
        listen       443;
        server_name  yourdomain;
 
        ssl                  on;
        ssl_certificate      nginx.pem;
        ssl_certificate_key  nginx.key;
 
        ssl_session_timeout  5m;
 
        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;
 
        add_header      Front-End-Https on;
        root /xxx;
 
        set $rewriteHttp "yes";
 
    location / {
        if ($request_uri ~* ^/wp-login.php) {
            set $rewriteHttp "no";
        }
        if ($request_uri ~* ^/wp-admin) {
            set $rewriteHttp "no";
        }
        if ($rewriteHttp ~ ^yes$) {
                        rewrite ^ http://$host$request_uri permanent;
        }
        index index.html index.htm index.php;
 
        }
 
        location ~.*\.(php|php5)?$ {
                fastcgi_pass unix:/tmp/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
}

参考资料:

1、 SSL Certificates with Nginx

2、 Administration Over SSL

觉得文章有用?立即:和朋友一起 共学习 共进步!

建议继续学习:

  1. 分享一个JQUERY颜色选择插件    (阅读:9761)
  2. WordPress评论翻页造成404页面的解决方案    (阅读:6180)
  3. jQuery Color Animations颜色动画插件    (阅读:6131)
  4. 精于图片处理的10款jQuery插件    (阅读:5481)
  5. vim 常用插件推荐    (阅读:5364)
  6. WordPress插件开发 -- 在插件使用数据库存储数据    (阅读:4701)
  7. WordPress安全建议    (阅读:4661)
  8. nyroModal:强大的jQuery弹出层插件    (阅读:4281)
  9. vim的一个js代码整理的插件jsbeautify.vim    (阅读:4028)
  10. WordPress插件开发--获知文章状态变化    (阅读:3922)

QQ技术交流群:445447336,欢迎加入!

扫一扫订阅我的微信号:IT技术博客大学习


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Head First Web Design

Head First Web Design

Ethan Watrall、Jeff Siarto / O’Reilly Media, Inc. / 2009-01-02 / USD 49.99

Want to know how to make your pages look beautiful, communicate your message effectively, guide visitors through your website with ease, and get everything approved by the accessibility and usability ......一起来看看 《Head First Web Design》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具