如何更改 apache Web 服务器中的默认根目录?

如何更改 apache Web 服务器中的默认根目录?

我正在尝试更改 Apache Web 服务器中的默认根目录,但从 Web 浏览器访问它时遇到问题。

禁用 SELinux

已停止的 IPTables

尝试将“/var/www/test/”设置为默认文件夹

在 cd /etc/httpd/conf/httpd.conf 中:我正在进行以下更改:

292 DocumentRoot "/var/www/test"

302 <Directory /var/www/test>
303     Options FollowSymLinks
304     AllowOverride None
305     Order allow,deny
306     Allow from all
307 </Directory>


317 # This should be changed to whatever you set DocumentRoot to.
318 #
319 <Directory "/var/www/test">

在 /var/www/ 下创建文件夹 test 并给出 chmod -R 755 /var/www/test/

重新启动httpd并重新启动,没有错误。

以下是一些日志实例:

访问日志:

192.168.1.18 - - [10/Jun/2015:18:27:00 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:18:27:04 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:18:27:40 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:18:27:47 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.1.18 - - [10/Jun/2015:18:27:47 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko"
192.168.1.18 - - [10/Jun/2015:18:31:06 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:18:31:09 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:18:31:27 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:18:45:29 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:19:00:10 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:19:00:12 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:19:00:13 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:19:06:33 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:19:06:37 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
192.168.1.18 - - [10/Jun/2015:19:26:22 -0500] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"

错误日志:

[Wed Jun 10 18:45:20 2015] [notice] Digest: generating secret for digest authentication ...
[Wed Jun 10 18:45:20 2015] [notice] Digest: done
[Wed Jun 10 18:45:20 2015] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations
[Wed Jun 10 18:45:25 2015] [notice] caught SIGTERM, shutting down
[Wed Jun 10 18:45:26 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Jun 10 18:45:26 2015] [notice] Digest: generating secret for digest authentication ...
[Wed Jun 10 18:45:26 2015] [notice] Digest: done
[Wed Jun 10 18:45:26 2015] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations
[Wed Jun 10 18:59:07 2015] [notice] caught SIGTERM, shutting down
[Wed Jun 10 19:00:05 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Jun 10 19:00:05 2015] [notice] Digest: generating secret for digest authentication ...
[Wed Jun 10 19:00:05 2015] [notice] Digest: done
[Wed Jun 10 19:00:05 2015] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations
[Wed Jun 10 19:00:08 2015] [notice] caught SIGTERM, shutting down
[Wed Jun 10 19:00:09 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Jun 10 19:00:09 2015] [notice] Digest: generating secret for digest authentication ...
[Wed Jun 10 19:00:09 2015] [notice] Digest: done
[Wed Jun 10 19:00:09 2015] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations
[Wed Jun 10 19:24:44 2015] [notice] caught SIGTERM, shutting down
[Wed Jun 10 19:24:45 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Jun 10 19:24:45 2015] [notice] Digest: generating secret for digest authentication ...
[Wed Jun 10 19:24:45 2015] [notice] Digest: done
[Wed Jun 10 19:24:45 2015] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations

答案1

我想将其写为评论而不是答案,但我还不能,所以请不要打扰我,社区。

到目前为止您发布的文章没有任何问题。错误日志显示重新启动apache后正常,并且您发布的访问日志中的304返回码也正常;它们表明所请求的资源与浏览器缓存的资源相比没有发生变化,因此不需要重新传输文档。

我启动了一个云服务器,并完全按照您指定的方式进行了更改,并从 /var/www/test 获取了带有文本“test”的 index.html。没有必要让 apache 成为目录的所有者,因为世界权限允许读取,这已经足够了。

因此,当您说访问该网站时遇到问题时,当您尝试访问该网站时,您到底看到了什么?日志显示私有 IP,这意味着您正在同一台计算机或本地网络上运行 apache;你是直接打IP吗?

答案2

您还需要将新创建的文件夹的所有者更改为apache或其他内容,具体取决于您的发行版。

相关内容