如何为特定目录设置open_basedir [英] How to set for specific directory open_basedir

查看:149
本文介绍了如何为特定目录设置open_basedir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录/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.

我通常在apache配置文件(例如/etc/httpd/conf/httpd.conf)中进行设置.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆