問題描述
今天調試一個項目,項目放在webroot下面的javascript目錄,無論怎么設置都是403 You don't have permission to access /javascript/ on this server.
思考過程
首先第一反應,Google了錯誤You don't have permission to access /javascript/ on this server. ,然后發現大部分答案都說到了配置文件中的Directory設置。比如
<Directory /> Options FollowSymLinks AllowOverride All Order deny,allow Allow from all</Directory>
而我并不是整個webroot都不能訪問,其他所有的文件夾都可以訪問,就是目錄javascript文件夾沒有權限訪問,我的設置是
<Directory /home/hfx/workspace/> Options Indexes FollowSymLinks# AllowOverride None AllowOverride All Require all granted</Directory>
所以按理來說也是沒有問題的,可以單單就是javascript目錄無法訪問,并且我嘗試重新給javascript目錄設置權限
chmod 777 -R javascript
然而還是并沒有什么卵用,于是我嘗試更改javascript變成javascript或者新建其他的名字的文件夾,而它們均可以正常訪問,所以猜想癥結應該是那里的配置禁止了web根路徑下名字為javascript的路徑。
發現問題
于是我看apache的所有配置文件,打開/etc/apache2/conf-enable/目錄,發現了一個名為javascript-common.conf的配置文件,打開一看
Alias /javascript /usr/share/javascript/<Directory "/usr/share/javascript/"> Options FollowSymLinks MultiViews</Directory>
其實我并不知道具體是什么意思,可是從字面意思大概看出,配置里面指定了一個別名/javascript到目錄/usr/share/javascript/,應該訪問/javascript就變成了訪問目錄/usr/share/javascript/而不是我們在web根目錄下創建的javascript目錄。
解決方案
于是google一下javascript-common.conf,這才發現了很多真正與此相關的問題,所以真正的解決方案有很多種,有的直接修改別名的名稱為/javascript-common,而我覺得最好的解決方案應該是
You don't need to edit the conf file or purge the package just disable it.
a2disconf javascript-commonservice apache2 reload
If for some reason you want to use that conf:
a2enconf javascript-commonservice apache2 reload
另外解釋一下a2disconf和a2enconf的作用,官方的介紹是
a2enconf, a2disconf - enable or disable an apache2 configuration file
從介紹就直接明了它的作用了。快捷的啟用或者禁用一個apache模塊。
另外還有類似的幾個命令:
apache2ctl - Apache HTTP server control interface a2enmod, a2dismod - enable or disable an apache2 module總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
新聞熱點
疑難解答