首页 > CMS > Wordpress > 正文

Nginx下WordPress附件目录禁止运行PHP

2024-09-07 00:51:57
字体:大 中 小
来源:转载
供稿:网友

WordPress的市场巨大,被各种坏人盯上,可能哪天你的程序附件目录里面就被上传了木马,通常被植入了PHP文件,然后远程执行,娃哈哈,懂的,如果把WordPress附件目录里面的PHP禁止运行,就不用担心了.

我用的是nginx,说说禁止方法:

  1. location /wp-content/uploads/ { 
  2.  
  3. location ~ .*/.(php)?$ { 
  4.  
  5. deny all; 
  6.  
  7. } 
  8.  
  9. } 

插入你的nginx conf中,重启nginx即可.

附上一个完整的虚拟主机的例子供参考:

  1. server 
  2.  
  3. { 
  4.  
  5. listen 80; 
  6.  
  7. server_name bbs.vpser.net; 
  8.  
  9. index index.html index.htm index.php; 
  10.  
  11. root /home/wwwroot/Vevb.com;include discuz.conf; 
  12.  
  13. location /wp-content/uploads/ { 
  14.  
  15. location ~ .*/.(php)?$ { 
  16.  
  17. deny all; 
  18.  
  19. } 
  20.  
  21. location ~ .*.(php 
  22.  
  23. php5)?$ 
  24.  
  25. { 
  26.  
  27. fastcgi_pass unix:/tmp/php-cgi.sock; 
  28.  
  29. fastcgi_index index.php; 
  30.  
  31. include fcgi.conf; 
  32.  
  33. } 
  34.  
  35. access_log off; 
  36.  
  37. } 

添加完执行:/usr/local/nginx/sbin/nginx -t测试配置文件,执行:/usr/local/nginx/sbin/nginx -s reload 载入配置文件使其生效.​

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表