LINUX上Apache访问不了个人网址出现403错误
2014-07-24 13:15
344 查看
今天安装了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
这样也可以访问网页了.
一.先说一下安装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
这样也可以访问网页了.
相关文章推荐
- Apache 在更改DocumentRoot,或新增虚拟目录之后出现403错误的解决方法汇总详解(Linux)
- Apache修改DocumentRoot后访问页面出现403错误的解决办法
- apache默认配置 访问目录403错误 出现You don't have permission to access / on this server
- Linux下Apache配置局域网访问出现的问题
- linux 下nginx+ftp搭建图片服务器在本机访问出现403错误的解决办法
- Apache 在更改DocumentRoot,或新增虚拟目录之后出现403错误的解决方法汇总详解(Linux)
- 使用Apache搭 16ca 建一个个人的静态网址,网址里面的内容是:i like linux
- linux运行apache出现403错误
- apache配置php后访问localhost出现403错误
- Apache 在更改DocumentRoot,或新增虚拟目录之后出现403错误的解决方法汇总详解(Linux)
- Apache的ANT Project的主页访问的时候总是出现问题,还是把它的镜像站点记下来的好!
- Linux+mono+Apache访问SQLServer数据库和Oracle数据库
- linux + apache + php 虚拟主机禁止php访问的方法
- 实例解决XPage访问出现HTTP403错误的问题
- linux下使用Apache为用户搭建个人主页
- 今早Linux系统重启apache出现VirtualHost overlap on port 80
- Linux下文件如果没有权限不能被Apache访问
- Linux下C++访问mysql出现函数undefined reference
- 傻瓜式解决Apache 2.2在windows上使用时出现403错误
- linux下安装svn集成到APACHE上时,启动apache出现:undefined symbol: db_create的错误处理