php多站点配置以及Forbidden You don't have permission to access / on this server问题解决

php多站点配置以及Forbidden You don't have permission to access / on this server问题解决

1、总结

一句话总结:个人问题是php的版本问题

php 版本
改变因素

找到问题的缘由了,我把php的版本从5.4.45切换成了 5.6.27,切换回来以后就行了,php文件就能解析了,网站就能访问了php

和配置实在没有半毛钱关系html

 

收获吧:仔细思考你作了哪些改变因素(在正确和错误之间),我忘记我切换了版本git

实际上是我没有意识到php版本切换会形成网站没法访问的问题github

由于php文件自己就是靠服务器来解析的,php版本切换确定有可能会形成网站没法访问apache

 

一、apache 设置目录不可访问,具体目录下的文件能够访问?

以前访问部分网站,会出现这种状况,若是没有具体的访问文件,就会默认跳转到根目录这样不少文件会暴露安全

因此要修改httpd.conf文件,服务器

Options Indexes FollowSymLinksmarkdown

修改成app

Options FollowSymLinkside

其实就是将Indexes去掉,Indexes表示若当前目录没有index.html就会显示目录结构

 

二、apache+php配置多站点?

httpd.conf
httpd-vhosts.conf
hosts
    1. 在”C:\wamp\bin\apache\apache2.4.9\conf“目录下打开httpd.conf配置文件
      大概516行左右在找到
      # Virtual hosts
      #Include conf/extra/httpd-vhosts.conf
      把include 的注释去掉,让他去加载conf/extra/httpd-vhosts.conf文件

    2. 在”C:\wamp\bin\apache\apache2.4.9\conf\extra“目录打开
      httpd-vhosts.conf文件,直接在这里配置站点
      上面所有注释,第一句
      NameVirtualHost *:80(设置端口号)
      # #如下是本身配置的站点1
      < VirtualHost *:80 >
      ServerName www.xiaozheng.com (网站的域名)
      DocumentRoot “C:\wamp\www” (文件的路径)
      < Directory “C:\wamp\www” > (文件的路径)
      Options Indexes
      Order allow,deny
      Allow from all
      Satisfy all
      < /Directory >
      < /VirtualHost >

      3.在“C:\Windows\System32\drivers\etc”的hosts文件里面配置
      就能够了

 

 

 

2、php多站点配置以及Forbidden You don't have permission to access / on this server问题解决

问题一:

前几天在电脑上配置多站点的后忽然出现了:”You don’t have permission to access / on this server!“ 究其缘由是:swampserver默认访问的是www文件夹的站点,不容许访问其余的站点。

问题一解决方法:

first:首先教你如何配置多站点

  1. 在”C:\wamp\bin\apache\apache2.4.9\conf“目录下打开httpd.conf配置文件
    大概516行左右在找到
    # Virtual hosts
    #Include conf/extra/httpd-vhosts.conf
    把include 的注释去掉,让他去加载conf/extra/httpd-vhosts.conf文件

  2. 在”C:\wamp\bin\apache\apache2.4.9\conf\extra“目录打开
    httpd-vhosts.conf文件,直接在这里配置站点
    上面所有注释,第一句
    NameVirtualHost *:80(设置端口号)
    # #如下是本身配置的站点1
    < VirtualHost *:80 >
    ServerName www.xiaozheng.com (网站的域名)
    DocumentRoot “C:\wamp\www” (文件的路径)
    < Directory “C:\wamp\www” > (文件的路径)
    Options Indexes
    Order allow,deny
    Allow from all
    Satisfy all
    < /Directory >
    < /VirtualHost >

    3.在“C:\Windows\System32\drivers\etc”的hosts文件里面配置
    就能够了

 

问题二:

若是类似配置的时候出现了这样的一个问题~~若是说个人文件路径在wamp\www之外的话,好比“F:\xiaozheng”会出现“You don’t have permission to access / on this server!”问腿!接下来如何解决这个问题

问题二解决方法:

首先:swampserver服务器默认是只能访问站内的文件夹,在http.conf文件里面有
< Directory />
AllowOverride all
Require all denied (拒绝了外部的访问)
< /Directory >
必须把上面的改为:
< Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
#Deny from all
Allow from all
#容许全部访问
Satisfy all
< /Directory>

第二步:
< Directory “D:/Wamp5/www”>

#
# 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.2/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 all

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

< /Directory>

修改为

< Directory “D:/Wamp5/www”>

#
# 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.2/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 all

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

# Allow from 127.0.0.1
Allow from all

< /Directory>

实际上是能够把一些没必要要的注释删掉的,我是把那些注释删掉了,简洁了好多,配图
这里写图片描述

或者还有一种新的解决方法,在httpd-vhosts.conf配置站点的时候这样配置
< VirtualHost *:80 >
ServerName www.xiaozheng.com
DocumentRoot “C:\wamp\www”

<Directory "C:\wamp\www">
    Options Indexes FollowSymLinks   #原先是Options Indexes
    AllowOverride all                #原先是没有这句的,这两句不论是否超出先限制的文件
                                     范围,均可以访问,就不会出现权限问题了
    Order allow,deny
 Allow from all Satisfy all
</Directory>

< /VirtualHost>

而后保存,重启服务,在访问就解决了这个问题。

 

参考:php多站点配置以及Forbidden You don't have permission to access / on this server问题解决 - xiaozhegaa的博客 - CSDN博客
https://blog.csdn.net/xiaozhegaa/article/details/52512477

 

 

3、解决Forbidden You don't have permission to access /index.php on this server.错误实测

一、问题描述

好久没用笔记本作开发了(3-4个月),此次换回笔记本开发,本机配置好服务器访问网站时,能进入目录,可是进入具体的index.php会出现Forbidden You don't have permission to access /index.php on this server.错误

具体以下图所示:

 

 

 

二、解决问题思路及过程

a、排查出错位置

分别试了www.blog.com:81和www.mo.com:81都是一样能访问目录不能访问index.php的问题,推测网站统一配置出现问题的状况比较大,固然也不排除这两个网站都设置错误的问题

 

开启了虚拟配置

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

 

上述两个网站在conf/extra/httpd-vhosts.conf中的配置以下:

<VirtualHost *:81>
    
    DocumentRoot "E:\2017-02-21--SoftWare\PHP\SOFTWARE\phpStudy_New\PHPTutorial\WWW\github\personalBlog\personalBlog\public"
    ServerName www.blog.com
    <Directory "E:\2017-02-21--SoftWare\PHP\SOFTWARE\phpStudy_New\PHPTutorial\WWW\github\personalBlog\personalBlog\public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
</VirtualHost>


<VirtualHost *:81>
    
    DocumentRoot "E:\2017-02-21--SoftWare\PHP\SOFTWARE\phpStudy_New\PHPTutorial\WWW\mo\m_Orchestrate\m_Orchestrate\public"
    ServerName www.mo.com
    <Directory "E:\2017-02-21--SoftWare\PHP\SOFTWARE\phpStudy_New\PHPTutorial\WWW\mo\m_Orchestrate\m_Orchestrate\public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Allow from all
    </Directory>
    
</VirtualHost>

我以前是用这样的配置进行的开发,没出现问题,惟一的变量只是好久没用这台电脑而已

也多是后面我对apache的配置文件作了什么修改我忘记了而已

 

权限配置中三句话的意思为:

Options Indexes FollowSymLinks
AllowOverride All
Allow from all

参照下面其它的配置,很容易知道这三句话的意思

<Directory "/applications/apache2.2.31/htdocs"> 站点目录(如下为默认站点目录的限制,若是读者私自配置了站点目录而没有配置这里就会出现 403错误)
Options Indexes FollowSymLinks FollowSymLinks表示容许符号连接,indexes表示容许目录浏览,如容许目录浏览,容许符号连接
这里很危险,应禁止目录浏览 应更改成 Options FollowSymLinks或Options -Indexes FollowSymLinks
AllowOverride None 表示禁止用户对目录配置文件(.htaccess进行修改)重载 尽可能不开启.htaccess 安全隐患大,规则多了网站访问性能低
Order allow,deny 拒绝未被明确容许的 (从后往前读)
Allow from all 全部人都能访问
</Directory>

 

将www.blog.com:81对用配置中的:Options Indexes FollowSymLinks改为Options -Indexes FollowSymLinks(在Indexs前面加了-)后,www.blog.com:81对应的目录没法访问:

其实检查的时候才发现,在在Indexs前面加了-后,apache启动失败了,这里看到的效果是apache启动失败

 

把apache配置文件httpd,conf中的下面这句话前面的#号去掉,以便访问网站的时候直接进入文件,而不是目录

<IfModule dir_module>
#    DirectoryIndex index.html index.php index.htm l.php
</IfModule>

 

.

localhost:81也不行

 

 

在apache的配置httpd.conf中,网站根路径的配置以下:

DocumentRoot  "E:\2017-02-21--SoftWare\PHP\SOFTWARE\phpStudy_New\PHPTutorial\WWW"
<Directory />
    Options +Indexes +FollowSymLinks +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

 

 

如今出现的问题就是:apache 网站 目录能够访问 文件不能访问

 

进一步检查,发现txt,xml格式的文件都能访问,php格式的文件不能访问

 

找到问题的缘由了,我把php的版本从5.4.45切换成了 5.6.27,切换回来以后就行了,php文件就能解析了,网站就能访问了

 

 

 

 

三、解决问题方法(最终解决)

找到问题的缘由了,我把php的版本从5.4.45切换成了 5.6.27,切换回来以后就行了,php文件就能解析了,网站就能访问了

和配置实在没有半毛钱关系

 

收获吧:仔细思考你作了哪些改变因素(在正确和错误之间),我忘记我切换了版本

实际上是我没有意识到php版本切换会形成网站没法访问的问题

由于php文件自己就是靠服务器来解析的,php版本切换确定有可能会形成网站没法访问

相关文章
相关标签/搜索