DocumentRoot must be a directory 的解决办法

本文探讨了Apache HTTPD服务中DocumentRoot目录配置出现DocumentRootmustbeadirectory错误的原因及解决方案。主要涉及两种常见原因:目录名称包含中文字符和SELinux安全策略限制,并提供了相应的调整策略。若问题依旧存在,则建议禁用SELinux以解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.sina.com.cn/s/blog_4ab645500100txlj.html

今天在修改了一下httpd.conf文件的DocumentRoot目录后重启了httpd服务,却发现报错了。 DocumentRoot must be a directory 。刚开始以为是自己配置有问题,后来检查了好一遍并确认配置的DocumentRoot就是一个directory啊。哎,只好baidu一下了。呵呵,看来遇到过这种报错的人还真不少啊。总结起来有两种可能导致了DocumentRoot must be a directory报错。

1、DocumentRoot的目录配置中带有中文

如果你的DocumentRoot目录设置中有中文的话,请先修改成英文的试试吧。哈哈……如果还不行的话就请接着往下看吧。

2、SELinux的安全策略搞得鬼啊

这是因为系统启用了SELinux安全策略之后会把目录或文件设成各种类型, 如home_root_t和user_home_t类型等。因些apache的进程就没有权限而无法访问你刚才设置的DocumentRoot了。针对 Apache的进程SELinux的安全策略规定只能访问 httpd_sys_content_t类型的目录或文件。所以把目录或文件的策略类型改成httpd_sys_content_t就可以了。修改命令如下:

chcon ---t httpd_sys_content_t /data/coderbolg/

可以用  ls -laZ 来查看目录的策略类型是否修改成功。做好了这一步如果还报错,呵呵……那还得往下看。

3、禁用SELinux

如果你真的被SELinux折磨的没有办法了。那就直接禁用SELinux吧。系统的不安全总比服务器不能访问的权重要低些吧。直接编辑SELinux的配置文件。

vim /etc/sysconfig/selinux

把SELINUX的值从enforcing改成disabled就行。存盘退出。这回一定可以了,如果还不可以就重启一下服务器吧。

 

# # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so "logs/access_log" # with ServerRoot set to "/usr/local/apache2" will be interpreted by the # server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" # will be interpreted as '/logs/access_log'. # # NOTE: Where filenames are specified, you must use forward slashes # instead of backslashes (e.g., "c:/apache" instead of "c:\apache"). # If a drive letter is omitted, the drive on which httpd.exe is located # will be used by default. It is recommended that you always supply # an explicit drive letter in absolute paths to avoid confusion. # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non-local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same ServerRoot for multiple httpd daemons, you will need to change at # least PidFile. # Define SRVROOT "E:/Apache24" ServerRoot "${SRVROOT}" # # Mutex: Allows you to set the mutex mechanism and mutex file directory # for individual mutexes, or change the global defaul
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值