我在虚拟主机上运行 Wordpress 时遇到了麻烦。当我尝试访问虚拟主机时,我收到“403 禁止访问,您无权访问此服务器上的 /。”错误,并且错误日志中出现“无法提供目录...”错误(见下文)。为什么我收到“403 禁止访问”错误?我遗漏了某些内容,希望您能看得出来(当然,我看不出来)。感谢您的帮助。
我安装了 Fedora 20 的最小版本(即没有 Gnome/KDE,但有很多 php 包 [710],所以它不是那么简陋)。然后我安装了 Apache,并按照以下说明安装了 Wordpresshttp://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install从那时起,我一直在 /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 [email protected]
DocumentRoot /var/www/html
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
IncludeOptional conf.d/*.conf
答案1
答案2
在日志中你可以发现一个错误
[2017 年 12 月 3 日星期日 17:38:17.649269] [autoindex:error] [pid 4806] [客户端::1:57323] AH01276:无法提供目录 /etc/httpd/conf/htdocs/:未找到匹配的 DirectoryIndex(),并且 Options 指令禁止服务器生成的目录索引
要解决这个问题:-
那么您必须删除 /etc/httpd/conf.d/welcome.conf 中的行
以下现有配置:-
<LocationMatch "^/+$"> Options -Indexes ErrorDocument 403 /.noindex.html </LocationMatch>
通过以下配置解决:- 注释掉一行。
<LocationMatch "^/+$"> #Options -Indexes ErrorDocument 403 /.noindex.html </LocationMatch>