wordpress在nginx下权限设置和安全总结

1、wordpress 权限对安装和使用效果的影响很大:权限错误将影响theme的安装:不能安装theme或者修改theme或删除theme。

相关设置:

chmod 755 wordpress

find wordpress -type d  -exec chmod 755 {} \;

find wordpress -iname “*.php”  -exec chmod 644 {} \;

chown -R nginx:nginx wordpress

方法见: http://my.oschina.net/kjpioo/blog/162697

2、 uploads目录 安全:

问题描述:linux 下 最新版  wordpress ,上传theme,theme安装成功后,在 wordpress/wp-content/uploads/ 目录下有 2013/09/theme_name.zip 文件存在。  虽然 2013/09/ 目录都是禁止list的,但是如何禁止 theme_name.zip 文件被客户端窥探到(防止被下载)

解决方案:

方案1:每次上传和安装好theme 后,手动删除 uploads的  .zip文件

方案2:在uploads目录下用 .htaccess的 Rewrite 规则,可以对http://SITE_URL/uploads/2013/09/theme_name.zip 的访问 进行屏蔽。

在apache上.htaccess转向,只要apache编译的时候指明支持rewrite模块即可。

但是换到nginx上方法会有不同,有人说把.htaccess转向规则写到nginx的配置文件里面,官方提供的方法之一,肯定可行的。
不过,此方法有个问题:不方便,下次要更改一个伪静态转向规则的时候还得去nginx的配置文件或者nginx的虚拟网站的配置文件里面去改,相比apache直接在目录下放置.htaccess文件,nginx的这个办法显然很原始。

解决方法:
在nginx的配置文件中include .htacces文件就可以实现相同的功能了。

举个例子,要把www.jbxue.com的.htaccess迁移到nginx上,几个步骤:

第一步:修改.htaccess文件,因为apache的rewrite转向规则跟nginx的转向规则还是有一些不一样的,典型的不一样有nginx的根目录需要写在每行转向的地址前,每行规则必须以分号(;)结束,301或者404等跳转使用不同的格式。

apache上htaccess转换到nginx上:

代码示例:

RewriteEngine On
RewriteBase /
RewriteRule ^show-([0-9]+)-([0-9]+)\.html$ index.php?action=show&id=$1&page=$2
RewriteRule ^category-([0-9]+)-([0-9]+)\.html$ index.php?action=index&cid=$1&page=$2
RewriteRule ^archives-([0-9]+)-([0-9]+)\.html$ index.php?action=index&setdate=$1&page=$2
RewriteRule ^(archives|search|reg|login|index|links)\.html$ index.php?action=$1
RewriteRule ^(comments|tagslist|trackbacks|index)-([0-9]+)\.html$ index.php?action=$1&page=$2
rewriteCond %{http_host} ^jbxue.com [NC]
rewriteRule ^(.*)$ http://www.jbxue.com/$1 [R=301,L]
ErrorDocument 404 http://www.jbxue.com/

转换成nginx的规则

代码示例:

rewrite ^/show-([0-9]+)-([0-9]+)\.html$ /index.php?action=show&id=$1&page=$2;
rewrite ^/category-([0-9]+)-([0-9]+)\.html$ /index.php?action=index&cid=$1&page=$2;
rewrite ^/archives-([0-9]+)-([0-9]+)\.html$ /index.php?action=index&setdate=$1&page=$2;
rewrite ^/(archives|search|reg|login|index|links)\.html$ /index.php?action=$1;
rewrite ^/(comments|tagslist|trackbacks|index)-([0-9]+)\.html$ /index.php?action=$1&page=$2;
if ($host != ‘www.jbxue.com’ ) {
rewrite ^/(.*)$ http://www.jbxue.com/$1 permanent;
}
error_page  404 http://www.jbxue.com/;

第二步:修改nginx的配置文件,增加include该.htaccess文件
vi /etc/nginx/sites-available/www.jbxue.com
增加一行:

代码示例:

include /var/www/www.jbxuecom/.htaccess

修改为相应的地址。

第三步:测试并重启

代码示例:

/etc/init.d/nginx -configtest

重启生效:

代码示例:

/etc/init.d/nginx  restart

 

5 Comments

  • action fat burner

    2016年4月30日 at 下午7:49 回复

    For the reason that the admin of this website is working, no
    doubt very shortly it will be famous, due to its feature contents.

  • comment-41432

    2016年4月30日 at 下午11:40 回复

    Its such ass you read my thoughts! You appear to understand a lot approximately this,
    like you wrote the e book in it or something. I
    feel thzt youu simply could do with some p.c. too force tthe message
    house a little bit, but instead of that, this is wonderful blog.A fantastic read.
    I will certainly be back.

  • Cliquez sur le site internet suivant

    2016年5月1日 at 下午5:15 回复

    Avant d’entrer dans les directions pour le hack starcoin, Nous voulons
    juste que chacun sache remark que cet outil a été testé maintes
    et maintes fois pour travailler sur plusieurs plates-formes et périphériques.

  • http://oyskainstitute.com

    2016年5月1日 at 下午8:38 回复

    Wow, that’s what I was exploring for, what a material!
    existing here at this weblog, thanks admin of this
    website.

  • Nautec

    2016年5月2日 at 上午7:16 回复

    Greetings! I’ve been following your weblog for a while now
    and finally got the bravery to go ahead and give you a shout out from Kingwood Texas!
    Just wanted to mention keep up the fantastic job!