如何拒绝访问目录中的php文件? nginx的

前端之家收集整理的这篇文章主要介绍了如何拒绝访问目录中的php文件? nginx的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试了很多配置的变种,但我仍然无法让它按预期工作.有什么建议?
  1. location ~ /views/(.+)\.PHP${
  2. deny all;
  3. }

配置:

  1. server {
  2. listen 80;
  3. server_name ...;
  4.  
  5. #charset koi8-r;
  6.  
  7. #access_log logs/host.access.log main;
  8.  
  9. location / {
  10. root /srv/www;
  11. index index.PHP index.html index.htm;
  12. }
  13.  
  14. error_page 404 /404.html;
  15. location = /404.html {
  16. root /usr/share/Nginx/html;
  17. }
  18.  
  19. # redirect server error pages to the static page /50x.html
  20. #
  21. error_page 500 502 503 504 /50x.html;
  22. location = /50x.html {
  23. root /usr/share/Nginx/html;
  24. }
  25.  
  26. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  27. #
  28. location ~ \.PHP${
  29. # root html;
  30. include fastcgi_params;
  31. fastcgi_pass 127.0.0.1:9000;
  32. fastcgi_index index.PHP;
  33. fastcgi_param SCRIPT_FILENAME /srv/www$fastcgi_script_name;
  34. }
  35.  
  36.  
  37. if (!-e $request_filename){
  38. rewrite ^/([0-9]+)$/get.PHP?get=$1 last;
  39. rewrite ^/add$/add.PHP;
  40. rewrite ^/RSS$/RSS.PHP;
  41. }
  42.  
  43. location ~ /views/(.+)\.PHP${
  44. deny all;
  45. }
  46. }
网址与其他位置匹配.发布配置文件.

交换位置(正则表达式按配置文件中定义的顺序检查):

  1. location ~ /views/(.+)\.PHP${
  2. deny all;
  3. }
  4. location ~ \.PHP${
  5. .....

猜你在找的PHP相关文章