Apache httpd服务器问题集合
来源:互联网 发布:淘宝网店推能学会吗 编辑:程序博客网 时间:2024/05/22 07:41
403 Forbidden
via: http://www.cnblogs.com/starof/p/4685999.html
问题描述
在apache2的httpd配置中,很多情况都会出现403。
刚安装好httpd服务,当然是不会有403的问题了。主要是修改了一些配置后出现,问题描述如下:
- 修改了DocumentRoot目录指向后,站点出现403错误。
- 设置了虚拟主机目录也可能导致403。
- apache的httpd服务成功启动,看起来都很正常,却没有权限访问
- 日志出现:
access to / denied (filesystem path '/srv/lxyproject/wsgi/django.wsgi') because search permissions are missing on a component of the path
- 设置虚拟目录后,错误日志出现:
client denied by server configuration: /srv/lxyproject/wsgi/django.wsgi
分析问题及方案
httpd.conf中目录配置文件
更改了DocumentRoot
比如改为 “/usr/local/site/test
” 。site目录和test目录是通过使用mkdir建立的,然后在test目录下放一个index.html。这种情况应该查看httpd.conf中配置。
你的<Directory "/usr/local/site/test">
一定要和DocumentRoot
一致,因为这段Directory是apache对该目录访问权限的设置,只有设置正确的目录,DocumentRoot才会生效。
<Directory "/usr/local/site/test"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted</Directory>
目录访问权限
第一步配置正确还是出现403,检查目录配置<Directory "/usr/local/site/test">
中是否有Deny from all
。有则所有访问都会被拒绝,当然403了。
可以设置为Allow from all
或者Require all granted
来处理。
不要修改<Directory />
根目录中Deny from all
。
目录权限
如果至此还是403,可能是网站目录的权限问题。
apache要求目录具有执行权限,也就是x,要注意的是,你的目录树都应该拥有这些权限。
假如你的目录是/usr/local/site/test
,那么要保证/usr
、/usr/local
、/usr/local/site
、/usr/local/site/test
这四个层级的目录都是755权限。
今天我遇到的就是这个问题了。
#chmod 755 /usr/local/site#chmod 755 /usr/local/site/test
我犯过一个错就是只设置了最后一级目录权限,没有设置上级目录权限,导致403。
虚拟目录
【这个问题我没遇到过,因为我没这样写过,网上资料这么写,可作为参考】
如果设置的是虚拟目录,那么你需要在httpd.conf中定义一个虚拟目录,而且像极了如下的片段:
Alias /folder "/usr/local/folder" <Directory "/usr/local/folder"> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.1 192.168.1.1 </Directory>
如果是这一种情况,而且你写得类似我上面的代码,三处folder都是一样一样的,那绝对会是403!怎么解决呢,就是把跟在Alias后面斜杠后面的那串改了,改成什么,不要和虚拟目录的文件夹同名就好,然后我就可以用改过后的虚拟目录访问了,当然,改文件夹也行,只要你不怕麻烦,只要Alias后面的虚拟目录定义字符(红色)和实际文件夹名(黑色)不相同就OK。
selinux的问题
如果依然是403,那就是selinux在作怪了,于是,你可以把你的目录进行一下selinux权限设置。
#chcon -R -t httpd_sys_content_t /usr/local/site#chcon -R -t httpd_sys_content_t /usr/local/site/test
网上资料说不过,这一步大多不会发生。但我的问题确实是,可能跟系统有关,具体原理还不是很懂。
wsgi的问题
我的虚拟主机配置为:
<VirtualHost *:80>WSGIScriptAlias / /srv/lxyproject/wsgi/django.wsgiAlias /static/ /srv/lxyproject/collectedstatic/ServerName 10.1.101.31#ServerName example.com#ServerAlias www.example.com<Directory /srv/lxyproject/collectedstatic> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory><Directory /srv/lxyproject/wsgi/> Allow from all</Directory>ErrorLog /etc/httpd/logs/lxyproject.error.logLogLevel warn</VirtualHost>
我访问
log报错:
client denied by server configuration: /srv/lxyproject/wsgi/django.wsgi
这个问题是因为版本的原因,解决办法:
修改<Directory /srv/lxyproject/wsgi/>
中Allow from all
为Require all granted
。
2.3以下版本用Allow from all
;
2.3及以上版本为Require all granted
。
<Directory /home/aettool/aet/apache> <IfVersion < 2.3 > Order allow,deny Allow from all </IfVersion> <IfVersion >= 2.3> Require all granted </IfVersion></Directory>
参考:
http://stackoverflow.com/questions/17766595/403-forbidden-error-with-django-and-mod-wsgi
相似问题
Permission denied
和上面问题一样。
via:
http://wiki.apache.org/httpd/13PermissionDenied
Apache对访问到的各层级目录都要求644权限,要逐层向上把路径中所有层级目录都chmod 644 dir
Client denied by server configuration
via:
https://wiki.apache.org/httpd/ClientDeniedByServerConfiguration
针对Apache 2.2访问权限配置是
<Directory /var/www/example.com> Order deny,allow Deny from all</Directory>
针对2.4配置是
<Directory /var/www/example.com> Require all denied</Directory>
查看Apache版本
#sudo apachectl -v
- Apache httpd服务器问题集合
- apache httpd服务器403 forbidden的问题
- httpd-apache服务器配置
- Win10 配置Apache httpd服务器
- Apache (httpd)服务器防DDOS模块mod_evasive
- apache服务器httpd.conf配置技巧
- Android apache httpd 终端上的服务器
- 服务器 Apache中Httpd.conf详解
- CentOS7.0安装Apache服务器httpd
- CentOS7.0安装Apache服务器httpd
- ubuntu 安装apache和httpd服务器
- apache(httpd服务器)私人学习笔记
- linux服务器 中httpd Apache安装方法
- 一次关于Apache 的httpd.exe占用服务器CPU到100%的问题处理心酸历程
- apache httpd
- Apache启动不了,httpd: apr_sockaddr_info_get() failed for apache 启动问题
- Apache启动不了,httpd: apr_sockaddr_info_get() failed for apache 启动问题
- Apache服务器主要配置文件httpd.conf中文注释
- 使用DFS进行拓扑排序,如果可以完成的话,输出路径
- 深入研究java.lang.Class类
- 为什么对象 属性的refcount=2
- jdbc连接数据库
- PHP面试题
- Apache httpd服务器问题集合
- 2.1 线性表的定义、逻辑结构、基本操作
- PAT 1107. Social Clusters (30) 特殊问题+并查集+数量信息并查集
- 贪心算法
- JAVA语言接入短信验证码接口详细代码示例
- DroneKit教程(七):遥控信道覆盖
- source Insight 使用
- 亲测Mysql表结构为InnoDB类型从ibd文件恢复数据
- 【NOIP模板】KMP