本质上,我发现你可以通过“open_basedir”来防止一个有安全漏洞的站点修改/阅读另一个站点。
但是,当我上传媒体文件使用wordpress我得到了错误
[error] 3048#0: *42070 FastCGI sent in stderr: "PHP Warning: file_exists(): open_basedir restriction in effect. File(/tmp/php51UUIj) is not within the allowed path(s): (/var/www/wordpress-site) in /var/www/wordpress-site/wp-includes/functions.php on line 2505 PHP Warning: file_exists(): open_basedir restriction in effect. File(/tmp//TheFile.tmp) is not within the allowed path(s): (/var/www/wordpress-site) in /var/www/wordpress-site/wp-includes/functions.php on line 2340 PHP Warning: touch(): open_basedir restriction in effect. File(/tmp/TheFile.tmp) is not within the allowed path(s): (/var/www/wordpress-site) in /var/www/wordpress-site/wp-admin/includes/file.php on line 177" while reading response header from upstream, client: 69.196.169.22, server: wordpress-site.com, request: "POST /wp-admin/async-upload.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fastcgi/php-fcgi.socket:", host: "wordpress-site.com", referrer: "http://wordpress-site.com/wp-admin/media-upload.php?post_id=245&"
从nginx中删除这一行修复了它
fastcgi_param PHP_VALUE open_basedir=$document_root;
但是,这是因为open_basedir被禁用,现在一个网站的洞可以访问另一个网站的数据。 是否有可能有open_basedir,并允许wordpress移动/ tmp / somefile到自己的网站目录?
这是非常直接的,但解释它非常好:open_basedir就像尿尿裤子保持温暖。
是的,它可以防止file_get_contents等函数访问所需目录之外的任何内容。 但是我可以使用exec(“cat / etc / passwd”,$ res); 或者其他一些做类似事情的function。
但是,要回答你的问题,在PHP中这样做的方式是通过添加由冒号分隔的文件夹。 例如
"/var/www/horses.com:/tmp:/uploads"
把wordpress放在docroot / var / www / wordpress-site中的一个临时目录中,然后使用它。
不要将/ tmp /添加到允许的目录列表 – 这将是不安全的。