php多站點配置以及Forbidden You don't have permission to access / on this server問題解決
一、總結
一句話總結:我的問題是php的版本問題
php 版本
改變因素
找到問題的原因了,我把php的版本從5.4.45切換成了 5.6.27,切換回來之后就好了,php文件就能解析了,網站就能訪問了
和配置實在沒有半毛錢關系
收獲吧:仔細思考你做了哪些改變因素(在正確和錯誤之間),我忘記我切換了版本
其實是我沒有意識到php版本切換會造成網站無法訪問的問題
因為php文件本身就是靠服務器來解析的,php版本切換肯定有可能會造成網站無法訪問
1、apache 設置目錄不可訪問,具體目錄下的文件可以訪問?
之前訪問部分網站,會出現這種情況,如果沒有具體的訪問文件,就會默認跳轉到根目錄,這樣很多文件會暴露。
所以要修改httpd.conf文件,
Options Indexes FollowSymLinks
修改為
Options FollowSymLinks
其實就是將Indexes去掉,Indexes表示若當前目錄沒有index.html就會顯示目錄結構
2、apache+php配置多站點?
httpd.conf
httpd-vhosts.conf
hosts
-
在”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文件 -
在”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文件里面配置
就可以了
二、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:首先教你如何配置多站點
-
在”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文件 -
在”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
三、解決Forbidden You don't have permission to access /index.php on this server.錯誤實測
1、問題描述
很久沒用筆記本做開發了(3-4個月),這次換回筆記本開發,本機配置好服務器訪問網站時,能進入目錄,但是進入具體的index.php會出現Forbidden You don't have permission to access /index.php on this server.錯誤
具體如下圖所示:


2、解決問題思路及過程
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文件就能解析了,網站就能訪問了
3、解決問題方法(最終解決)
找到問題的原因了,我把php的版本從5.4.45切換成了 5.6.27,切換回來之后就好了,php文件就能解析了,網站就能訪問了
和配置實在沒有半毛錢關系
收獲吧:仔細思考你做了哪些改變因素(在正確和錯誤之間),我忘記我切換了版本
其實是我沒有意識到php版本切換會造成網站無法訪問的問題
因為php文件本身就是靠服務器來解析的,php版本切換肯定有可能會造成網站無法訪問
