nginx安全配置之白名单设置

jerry thinkphp 2015年11月19日 收藏
针对php设置一个可执行的白名单,对于服务器安全来说也是一种必要而重要的设置。
其他的不多说,直接上配置明细吧:
  1. server {
  2.     listen       5080;
  3.     server_name  www.example.com;

  4.     root         /home/htdocs/app/;
  5.     index        index.php;

  6.     location / {
  7.         try_files $uri $uri/ /index.php?s=$uri;
  8.     }

  9.     location ~ .*\.php$ {
  10.         # 白名单配置,只允许/index.php访问
  11.         if ($fastcgi_script_name !~* "^/(index)\.php$") {
  12.             return 403;
  13.         }
  14.         fastcgi_pass   127.0.0.1:9000;
  15.         fastcgi_index  index.php;
  16.         include        fcgi.conf;
  17.     }
  18. }
PS:发现发错地方了,请移动至话题讨论区去,感谢!