Nginx“”try_files“指令中的参数数量无效…”用于PHP安全性

前端之家收集整理的这篇文章主要介绍了Nginx“”try_files“指令中的参数数量无效…”用于PHP安全性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用debian风格的目录结构从我的共享主机的用户文件夹中的源代码运行Nginx.我尝试启动服务器时遇到错误

  1. [emerg] invalid number of arguments in "try_files" directive in /home/.../Nginx/conf/sites-enabled/default:11

引用的行是来自Nginx陷阱页面PHP执行保护.这是我的配置文件

Nginx.conf:

  1. worker_processes 1;
  2. events {
  3. worker_connections 1024;
  4. }
  5. http {
  6. sendfile on;
  7. tcp_nopush on;
  8. tcp_nodelay on;
  9. keepalive_timeout 65;
  10. types_hash_max_size 2048;
  11. client_max_body_size 5m;
  12. include /home/hittingsmoke/Nginx/conf/mime.types;
  13. default_type application/octet-stream;
  14. gzip on;
  15. gzip_disable \"msie6\";
  16. include /home/hittingsmoke/Nginx/conf/sites-enabled/*;
  17. }

…和sites-available / default:

  1. server {
  2. listen 12513;
  3. root /home/hittingsmoke/Nginx/html/;
  4. index index.PHP index.html index.htm;
  5. server_name _;
  6. location ~ \.PHP${
  7. try_files $uri =404;
  8. fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
  9. fastcgi_pass unix:/home/hittingsmoke/PHP-5.3/var/run/PHP5-fpm.sock;
  10. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  11. fastcgi_index index.PHP;
  12. include fastcgi_params;
  13. }
  14. # redirect server error pages to the static page /50x.html
  15. #
  16. error_page 500 502 503 504 /50x.html;
  17. location = /50x.html {
  18. root html;
  19. }
  20. }

我的配置找不到任何问题.我的设置几乎与我正在运行的Ubuntu机箱上的工作安装相同.我究竟做错了什么?

编辑:进一步测试,这只发生在我使用Nginx.conf中包含include的站点可用设置时.如果我将我的sites-available / default的内容复制/粘贴到我的Nginx.conf中,一切正常.

EDIT2:如上所述,如果我从vhosts文件删除了try_files,它会再次失败并在fastcgi_params上出现相同的错误.这是我的fastcgi_params文件内容.这都是默认的:

  1. fastcgi_param QUERY_STRING $query_string;
  2. fastcgi_param REQUEST_METHOD $request_method;
  3. fastcgi_param CONTENT_TYPE $content_type;
  4. fastcgi_param CONTENT_LENGTH $content_length;
  5. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  6. fastcgi_param REQUEST_URI $request_uri;
  7. fastcgi_param DOCUMENT_URI $document_uri;
  8. fastcgi_param DOCUMENT_ROOT $document_root;
  9. fastcgi_param SERVER_PROTOCOL $server_protocol;
  10. fastcgi_param HTTPS $https if_not_empty;
  11. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  12. fastcgi_param SERVER_SOFTWARE Nginx/$Nginx_version;
  13. fastcgi_param REMOTE_ADDR $remote_addr;
  14. fastcgi_param REMOTE_PORT $remote_port;
  15. fastcgi_param SERVER_ADDR $server_addr;
  16. fastcgi_param SERVER_PORT $server_port;
  17. fastcgi_param SERVER_NAME $server_name;
  18. # PHP only,required if PHP was built with --enable-force-cgi-redirect
  19. fastcgi_param REDIRECT_STATUS 200;

EDIT3:我犯了一个小错误.它是fastcgi_param,而不是fastcgi_param * s *,其中错误删除try_files指令后继续.

最佳答案
Nginx试图解释try_files指令至少需要两个路径:

  1. try_files /path1$uri /path2$uri ...

使用/ dev / null作为简单的解决方法

  1. try_files $uri /dev/null =404;

或者是一个允许更多自定义的命名位置:

  1. try_files $uri @error
  2. ...
  3. location @error {
  4. ...
  5. }

猜你在找的Nginx相关文章