li26598296 发表于 2018-11-21 12:37:45

解决apache 访问显示403

  
  
  配置虚拟主机之后访问站点。提示我没有权限访问权限
  一般情况下有以下几个问题;
  1,站点目录访问权限配置问题
  2, 目录权限问题
  3,路径问题

  提示我没有权限,解决思路,第一步检查站点目录权限设置
  

  

#tree

.

├── bbs

│   └── index.html

├── blog

│   └── index.html

└── www

    └── index.html



3 directories, 3 files

#ll

total 12

drwxrwxrwx 2 root root4096 Mar4 07:57 bbs

drwxrwxrwx 2 root root4096 Mar4 07:58 blog

drwxrwxrwx 2 root root4096 Mar4 07:58 www

我给目录最大权限。 777 依然报错

第二步检查我的配置的站点目录权限

#diff httpd.conf httpd.conf-2015-02

161,162c161,162

< User www

< Group www

---

> User daemon

> Group daemon

192c192

< ServerNamelocalhost:80

---

> #ServerNamewww.example.com:80

250c250

<   DirectoryIndex index.php index.html

---

>   DirectoryIndex index.html

275c275

< LogLevel error

---

> LogLevel warn

379,380d378

<   AddType application/x-httpd-php .php

<   AddType application/x-httpd-souce .phps

450c448

< Includeconf/extra/httpd-mpm.conf

---

> #Include conf/extra/httpd-mpm.conf

468c466

< Includeconf/extra/httpd-vhosts.conf

---

> #Includeconf/extra/httpd-vhosts.conf

507,513d504

<

<

<   Options FollowSymLinks

<   AllowOverride None

<   Order allow,deny

<   Allow from all

<

#/etc/init.d/httpd graceful

访问

You don't havepermission to access / on this server.   网页显示403 禁止访问

查看解析

20.0.0.10    www.wangxing.org

20.0.0.10    bbs.wangxing.org

20.0.0.10    blog.wangxing.org

客户端解析

检查解析ok

防火墙:

#/etc/init.d/iptables status

iptables: Firewall isnot running.

#/etc/init.d/iptables stop

#getenforce

Disabled

查看源码

403 错误

20.0.0.1 - - "GET /favicon.ico HTTP/1.1" 403 220

20.0.0.1 - - "GET / HTTP/1.1" 403 209

20.0.0.1 - - "GET /favicon.ico HTTP/1.1" 403 220

20.0.0.1 - - "GET / HTTP/1.1" 403 209

20.0.0.1 - - "GET /favicon.ico HTTP/1.1" 403 220

20.0.0.1 - - "GET / HTTP/1.1" 403 209

20.0.0.1 - - "GET /favicon.icoHTTP/1.1" 403 220

https://wiki.apache.org/httpd/ClientDeniedByServerConfiguration查看官网修改内容



根据错误提示

Youdon't have permission to access / on this server.去官网查找原因

http://httpd.apache.org/docs/2.4/upgrading.html根据官网的资料修改权限之后ok.

查看apache的配置文件,httpd.conf



    AllowOverride none

    Requireall denied




这句话的意思是拒绝我/ 目录的访问,这可能是apache 2.4 版本的出于安全的考虑,对apache 的安全机制做了调整了,要想使用新版本软件,还是需要看版本说明和官网文档的。

http://httpd.apache.org/docs/2.4/upgrading.html ,但是很多情况下有些是默认的还是可以访问的,但是我的问题修改之后解决了,

总结,在配置虚拟主机和php设置的时候

1.       Apache 整合php配置

Php的官网建议采用以下配置文件作为添加



SetHandler application/x-httpd-php



将这句话添加到httpd.conf最后面,

还有php的源码过滤器,但是官网不建议在生产环境中去使用,出于对安全的考虑



    SetHandlerapplication/x-httpd-php-source



2,站点目录权限的配置

站点目录权限的配置可以添加在httpd.conf 中,也可以添加在httpd-vhosts.conf 文件中,





    Options FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow fromall



可以添加在虚拟配置文件中,也可以添加在虚拟配置文件最后面,

可以使用/usr/local/apache2/bin/apachectl –S 去检查虚拟主机的配置文件

然后使用/usr/local/apache2/bin/apachectlgraceful 去测试,

  

  

  备注:配置相关版本的apache最好查看官网手册




页: [1]
查看完整版本: 解决apache 访问显示403