热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

LINUX上Apache访问不了个人网址出现403错误

今天安装了Apache想访问linux服务器的静态网页,结果出现了如题的403错误,查找了大量的资料,总结了一下解决办法:一.先说一下安装Apache的步骤(如果已经安装完可以跳过第一步):

今天安装了Apache想访问linux服务器的静态网页,结果出现了如题的403错误,查找了大量的资料,总结了一下解决办法:

一.先说一下安装Apache的步骤(如果已经安装完可以跳过第一步):

1.安装之前先检查一下主机上是否已经安装了apache

         rpm -qa |grep httpd                         //httpd 是apache服务的名字

   如果什么也没显示,说明本机没有安装apache,那我们就可以进行安装了。

2.yum install httpd -y                    //使用yum安装apache非常的方便

chkconfig httpd on 

service httpd start                           //开启apache

这样apache就安装好了,服务也启动了 //ps -ef|grep httpd 可以查看启动

这时你在浏览器输入这台服务器的ip就会出来apache的欢迎页

二.访问个人网站

首先我的静态网页都在/home/yanwenliang这个目录下

要想访问必须修改配置文件,配置文件一般在/etc/httpd/cond/httpd.conf中

vi /etc/httpd/cond/httpd.conf可以看到里面的配置文件

     在第290行左右的地方可以看到如下内容:

     # DocumentRoot: The directory out of which you will serve your
     # documents. By default, all requests are taken from this directory, but
     # symbolic links and aliases may be used to point to other locations.
     #
        DocumentRoot "/var/www/html"

      这段内容就是设置你网页的默认路径

      所以将DocumentRoot "/var/www/html"改成DocumentRoot "/home/yanwenliang"就可以了。

      也就是将它给路径改成你存放网页的路径就可以了。

     在第340多行的地方有如下内容:

     # Controls who can get stuff from this server.
     #
     #   onlineoffline tag - don't remove
         Order Deny,Allow
         Allow from all

       如果是这样就不需要修改,如果它是Deny from all,那就改成Allow from all

修改完之后保存,重启service httpd restart,如果不出以外就可以访问网页了,在浏览器输入IP

可是总有意外,显示的还是欢迎页面。

三.于是我想到了可能是目录的权限读写问题,然后按照配置文件里面的要求改写

This usually means that ~userid must have permissions of 711, ~userid/public_html must have permissions of 755, and documents contained therein must be world-readable.Otherwise, the client will only receive a "403 Forbidden" message.

也就是将目录权限改成711,目录内的html文件等改成755。本以为这样就可以了,结果还是不行

四.于是又查了一点资料,了解到一个新词叫selinux,可能是它的问题,一查设置果然设置了安全访问

操作:

1.getenforce    //查询当前selinux的值,有三种结果:

# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled

2.setenforce  enforcing/permissive(或者setenforce 1/0效果一样)

就是切换模式,当我们把enforcing切换成permissive的时候,终于可以看到网页了。

注:上面第四部是最简单的方法,但是会带来一个安全的问题,所以我们也可不比把所有的权限都改掉,只改那一个文件夹的权限即可:

操作:ls -Z -d yanwenliang/

-rw-r--r--. root root unconfined_u:object_r:home_root_t:s0 yanwenliang/


chcon -R -t httpd_user_content_t yanwenliang/

drwx--x--x. root root unconfined_u:object_r:httpd_user_content_t:s0 yanwenliang/


ls -Z yanwenliang/

drwxr-xr-x. root root unconfined_u:object_r:httpd_user_content_t:s0 bin
drwxr-xr-x. root root unconfined_u:object_r:httpd_user_content_t:s0 build
-rwxr-xr-x. root root unconfined_u:object_r:httpd_user_content_t:s0 build.properties
-rwxr-xr-x. root root unconfined_u:object_r:httpd_user_content_t:s0 build.xml
-rwxr-xr-x. root root unconfined_u:object_r:httpd_user_content_t:s0 circle.yaml
drwxr-xr-x. root root unconfined_u:object_r:httpd_user_content_t:s0 coverage_report


这样也可以访问网页了.


推荐阅读
author-avatar
手机用户2502909293
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有