linux apache外网不能访问权限,httpd服务器提示无权限访问解决办法

在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.

#

#

#Options -Indexes

#ErrorDocument 403 /.noindex.html

#

#

#AllowOverride None

#Require all granted

#

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

#ServerNamewww.example.com:80

DocumentRoot “/home/www/html”

# Relax access to content within /var/www.

# 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#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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值