简体   繁体   English

如何设置特定目录open_basedir

[英]How to set for specific directory 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. 我有一个目录/htdocs/unsecured ,我想限制该目录或其子目录中的任何内容访问该目录之外的任何内容。 Where and how do I set open_basedir for this directory only? 我在哪里以及如何仅为此目录设置open_basedir

You can set open_basedir in your Apache configuration file, php.ini, or in a .htaccess file. 您可以在Apache配置文件,php.ini或.htaccess文件中设置open_basedir

I normally set this in an apache config file such as /etc/httpd/conf/httpd.conf. 我通常在一个apache配置文件中设置它,例如/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>

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 . 注: 123.123.123.123是您的域的IP地址该样品板可能遗漏了大量的数据对于该配置只显示所需的内容为open_basedir

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: 在php.ini中,您可以在更广泛的级别上执行此操作(并且它将应用于服务器上的每个域):

open_basedir = "/htdocs/unsecured"

In .htaccess, you should be able to use the following (though I haven't tested): 在.htaccess中,您应该能够使用以下内容(尽管我还没有测试过):

php_value open_basedir "/htdocs/unsecured"

EDIT (Windows path) 编辑 (Windows路径)
Per a comment, you're running xammp on Windows (and not using Virtual Hosts). 根据评论,您在Windows上运行xammp(而不是使用虚拟主机)。 With this information, I would suggest to put your open_basedir rule in your php.ini file. 有了这些信息,我建议将你的open_basedir规则放在你的php.ini文件中。 This should (hopefully) work for you: 这应该(希望)对你有用:

open_basedir = "C:\xampp\htdocs\unsecured"

In linux, a : is a field separator. 在linux中,a :是一个字段分隔符。 In Windows, the ; 在Windows中, ; is the separator - so this should work, but I am unable to test it personally. 是分隔符 - 所以这应该工作,但我无法亲自测试它。

您可以在httpd.conf中或运行时更改 php.ini中的open_basedir

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM