问题描述
我有一个目录 /htdocs/unsecured
并且我想限制该目录或其子目录中的任何内容访问该目录之外的任何内容.我在哪里以及如何仅为这个目录设置 open_basedir
?
I have a directory /htdocs/unsecured
and I want to limit whatever is in that directory or its subdirectories from accessing anything outside of that directory. Where and how do I set open_basedir
for this directory only?
推荐答案
您可以在 Apache 配置文件、php.ini 或 .htaccess 文件中设置 open_basedir
.
You can set open_basedir
in your Apache configuration file, php.ini, or in a .htaccess file.
我通常在/etc/httpd/conf/httpd.conf 等 apache 配置文件中设置它.
I normally set this in an apache config file such as /etc/httpd/conf/httpd.conf.
您将拥有当前域/虚拟主机的目录结构,您可以直接在其中添加该行:
You will have a directory structure for your current domain/virtual-host and you can add the line directly in there:
<VirtualHost 123.123.123.123:80>
<Directory /htdocs/unsecured>
php_admin_value open_basedir "C:/htdocs/unsecured"
</Directory>
</VirtualHost>
注意:123.123.123.123
是您域的 IP 地址和这个示例块可能会遗漏很多 数据仅显示 open_basedir
所需的内容.
Note: The 123.123.123.123
is the IP address of your domain and this sample block potentially leaves out a lot of data for this configuration only showing what's needed for open_basedir
.
在 php.ini 中,您可以在更一般的级别执行此操作(它将应用于您服务器上的每个域):
In php.ini, you can do this on a much-more general level (and it will be applied to every domain on your server) with:
open_basedir = "/htdocs/unsecured"
在 .htaccess 中,您应该可以使用以下内容(虽然我还没有测试过):
In .htaccess, you should be able to use the following (though I haven't tested):
php_value open_basedir "/htdocs/unsecured"
编辑(Windows 路径)
根据评论,您在 Windows 上运行 xammp(而不是使用虚拟主机).有了这些信息,我建议将您的 open_basedir
规则放在您的 php.ini
文件中.这应该(希望)对您有用:
EDIT (Windows path)
Per a comment, you're running xammp on Windows (and not using Virtual Hosts). With this information, I would suggest to put your open_basedir
rule in your php.ini
file. This should (hopefully) work for you:
open_basedir = "C:\xampp\htdocs\unsecured"
在 linux 中,:
是一个字段分隔符.在 Windows 中,;
是分隔符 - 所以这 应该 工作,但我无法亲自测试.
In linux, a :
is a field separator. In Windows, the ;
is the separator - so this should work, but I am unable to test it personally.
这篇关于如何为特定目录设置open_basedir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!