在CentOS 7.7上搭建httpd服务器,用于浏览访问服务器上的文件,将welcome.conf中部分内容注释掉。
[yiquan@localhost ~]$ cat /etc/httpd/conf.d/welcome.conf
#
# This configuration file enables the default “Welcome” page if there
# is no default index page present for the root URL. To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
#<LocationMatch “^/+$”>
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#</LocationMatch>
#<Directory /usr/share/httpd/noindex>
# AllowOverride None
# Require all granted
#</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
并将http root目录修改为/home/www/,不再使用系统默认的/var/www/.
[yiquan@localhost httpd]$ cat conf/httpd.conf |grep www
# with ServerRoot set to ‘/www‘ will be interpreted by the
# server as ‘/www/log/access_log’, where as ‘/log/access_log’ will be
#ServerName www.example.com:80
DocumentRoot “/home/www/html”
# Relax access to content within /var/www.
<Directory “/home/www“>
<Directory “/home/www/html”>
# Redirect permanent /foo http://www.example.com/bar
ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”
# “/var/www/cgi-bin” should be changed to whatever your ScriptAliased <Directory “/home/www/cgi-bin”> #ErrorDocument 402 http://www.example.com/subscription_info.html
首选确保新位置的目录/home/www的 用户和用户组与/var/www保持一致
[yiquan@localhost home]$ ls -lr
total 4
drwx——. 15 yiquan yiquan 4096 Apr 24 07:53 yiquan
drwxrwxrwx. 4 root root 33 Apr 24 07:45 www
[yiquan@localhost home]$ ls /var/www/ -l
total 0
drwxr-xr-x. 2 root root 6 Aug 8 2019 cgi-bin
drwxr-xr-x. 3 root root 21 Apr 24 07:39 html
[yiquan@localhost home]$ ls /var/ -l
total 12
drwxr-xr-x. 4 root root 33 Apr 24 07:32 www
drwxr-xr-x. 2 root root 6 Apr 11 2018 yp
[yiquan@localhost home]$
启动服务器后,提示访问无权限。
Forbidden
You don’t have permission to access / on this server.
看httpd日志,报错信息如下
[Fri Apr 24 07:55:12.053475 2020] [core:notice] [pid 10599] AH00094: Command line: ‘/usr/sbin/httpd -D FOREGROUND’
[Fri Apr 24 07:55:15.911754 2020] [autoindex:error] [pid 10600] (13)Permission denied: [client 192.168.168.39:51373] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 07:55:16.911478 2020] [autoindex:error] [pid 10600] (13)Permission denied: [client 192.168.168.39:51373] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 07:55:17.705638 2020] [autoindex:error] [pid 10600] (13)Permission denied: [client 192.168.168.39:51373] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 07:55:21.774518 2020] [autoindex:error] [pid 10601] (13)Permission denied: [client 192.168.168.39:51382] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 16:11:53.105026 2020] [autoindex:error] [pid 10602] (13)Permission denied: [client 192.168.168.70:51601] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 16:30:57.527610 2020] [autoindex:error] [pid 10603] (13)Permission denied: [client 106.11.31.222:54735] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 16:32:25.323590 2020] [autoindex:error] [pid 10628] (13)Permission denied: [client 106.11.31.222:42664] AH01275: Can’t open directory for index: /home/www/html/
[Fri Apr 24 16:32:27.218470 2020] [autoindex:error] [pid 10628] (13)Permission denied: [client 106.11.31.222:42664] AH01275: Can’t open directory for index: /home/www/html/
解决办法:
[yiquan@localhost html]$ chcon -R -t httpd_sys_content_t directory-name
Leave a Reply