Linux

Wordpress 和 Apache 2.4 安裝問題:Cannot Serve Directory

  • December 3, 2017

我在讓 Wordpress 在我的虛擬主機上執行時遇到了麻煩。當我嘗試訪問我的虛擬主機時,我收到“403 Forbidden You don’t have permission to access / on this server”。錯誤和我的錯誤日誌中的“無法提供目錄…”錯誤(見下文)。為什麼我會收到“403 Forbidden”?我遺漏了一些東西,希望對你很明顯(對我來說自然不是)。謝謝你的幫助。

我安裝了 Fedora 20 的最小安裝(即,沒有 Gnome/KDE,但有很多 php 包

$$ 710 $$所以它不是那麼瘦)。然後我安裝了 Apache,並按照http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install安裝了 Wordpress 。從那時起,我一直在 /etc/httpd 中尋找問題。 我有 Apache 2.4、php 5.5.18、Fedora 20 和 Wordpress 4.0-1。

我在 Apache 中創建了我的虛擬主機,這是我的錯誤日誌中的錯誤(全部在一行上):

[Sat Nov 15 20:38:16.067198 2014] [autoindex:error] [pid 6745] 
[client XX.XX.XX.XX:48419] AH01276: Cannot serve directory /usr/share/wordpress/: 
No matching DirectoryIndex (index.html) found, and server-generated directory
index forbidden by Options directive

我一直在破解和破解 httpd.conf 文件和我的虛擬主機文件(在 /etc/httpd/conf.d/myhostname.conf 中找到)無濟於事。有任何想法嗎?我包含了我的 httpd.conf 和我的虛擬主機的 conf 文件的(縮短的)副本。一、虛擬主機:

<VirtualHost *:80>
       ServerName virtual1.myhost.com
       ServerAlias virtual1
       DocumentRoot /usr/share/wordpress
       ErrorLog logs/virtual1_error
       CustomLog logs/virtual1_access common
</VirtualHost>

<Directory />
 Require all granted
 AllowOverride None
 <IfModule mod_rewrite.so>
       RewriteEngine On
       RewriteBase /
       RewriteRule ^index\.php$ - [L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule . /index.php [L]
 </IfModule>
</Directory>

<Directory /usr/share/wordpress>
 Require all granted
 <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /
       RewriteRule ^index\.php$ - [L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule . /index.php [L]
 </IfModule>
 Options FollowSymLinks
 AllowOverride None
#  <IfModule mod_authz_core.c>
#    # Apache 2.4
#    Require local
#  </IfModule>
#  <IfModule !mod_authz_core.c>
#    # Apache 2.4
#    Require all granted
#    AllowOverride None
# </IfModule>
</Directory>

<Directory /usr/share/wordpress/wp-content/plugins/akismet>
 <FilesMatch "\.(php|txt)$">
   Require all granted
   AllowOverride None
 </FilesMatch>
</Directory>

現在,httpd.conf:

#
ServerRoot "/etc/httpd"

Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
   AllowOverride none
   Require all granted
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
   AllowOverride None
   # Allow open access:
   Require all granted
</Directory>
<Directory "/var/www/html">
   Require all granted
   Options Indexes FollowSymLinks
   AllowOverride None
</Directory>
<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>
#
<Files ".ht*">
   Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   LogFormat "%h %l %u %t \"%r\" %>s %b" common
   <IfModule logio_module>
     # You need to enable mod_logio.c to use %I and %O
     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
   </IfModule>
   CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
   ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options None
   Require all granted
</Directory>
<IfModule mime_module>
   TypesConfig /etc/mime.types
   AddType application/x-compress .Z
   AddType application/x-gzip .gz .tgz
   AddType text/html .shtml
   AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8

<IfModule mime_magic_module>
   MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.myhost.com
   ServerAlias www
   ServerAdmin root@myhost.com
   DocumentRoot /var/www/html
   ErrorLog logs/error_log
   CustomLog logs/access_log common
</VirtualHost>

IncludeOptional conf.d/*.conf

看來你已經忘記了DirectoryIndex

這應該添加到<VirtualHost>服務 WordPress。

DirectoryIndex index.php

在日誌中你可以發現一個錯誤

$$ Sun Dec 03 17:38:17.649269 2017 $$ $$ autoindex:error $$ $$ pid 4806 $$ $$ client ::1:57323 $$AH01276: 無法提供目錄 /etc/httpd/conf/htdocs/: 找不到匹配的 DirectoryIndex (),並且伺服器生成的目錄索引被選項指令禁止 要解決這個問題:-

那麼您必須刪除 /etc/httpd/conf.d/welcome.conf 中的行

低於現有配置:- <LocationMatch "^/+$"> Options -Indexes ErrorDocument 403 /.noindex.html </LocationMatch>

使用以下配置解決,:-註釋掉一行。

<LocationMatch "^/+$"> #Options -Indexes ErrorDocument 403 /.noindex.html </LocationMatch>

引用自:https://serverfault.com/questions/644639