Debian11 VPS上Magento+Apache2遇RewriteEngine not allowed here错误求助
问题:Debian 11 VPS上Magento安装后触发500内部服务器错误
- 环境:Debian 11 VPS、Apache 2、PHP 8.1-FPM,Magento安装包与GitHub官方仓库原版一致
- 症状:安装完成后访问页面出现500内部服务器错误,ErrorDocument处理请求时也触发同类型错误
- 日志提示:
/home/elliot/web/magento.mywebsite.ie/public_html/magento2/.htaccess: RewriteEngine not allowed here - 排查结论:Magento根目录和pub目录(当前站点DocumentRoot)各有一个.htaccess文件,删除根目录的.htaccess后,错误提示变为“This page isn’t working”,推测Apache正在加载根目录的.htaccess
当前Apache SSL虚拟主机配置如下:
<VirtualHost 141.146.42.11:8443> ServerName magento.mywebsite.ie ServerAdmin info@magento.mywebsite.ie DocumentRoot /home/elliot/web/magento.mywebsite.ie/public_html/magento2/pub ScriptAlias /cgi-bin/ /home/elliot/web/magento.mywebsite.ie/cgi-bin/ Alias /vstats/ /home/elliot/web/magento.mywebsite.ie/stats/ Alias /error/ /home/elliot/web/magento.mywebsite.ie/document_errors/ #SuexecUserGroup elliot elliot CustomLog /var/log/apache2/domains/magento.mywebsite.ie.bytes bytes CustomLog /var/log/apache2/domains/magento.mywebsite.ie.log combined ErrorLog /var/log/apache2/domains/magento.mywebsite.ie.error.log <Directory /home/elliot/web/magento.mywebsite.ie/stats> AllowOverride All </Directory> <Directory /home/elliot/web/magento.mywebsite.ie/public_html/magento2/pub> AllowOverride All SSLRequireSSL Options +Includes -Indexes +ExecCGI </Directory> SSLEngine on SSLVerifyClient none SSLCertificateFile /home/elliot/conf/web/magento.mywebsite.ie/ssl/magento.mywebsite.ie.crt SSLCertificateKeyFile /home/elliot/conf/web/magento.mywebsite.ie/ssl/magento.mywebsite.ie.key SSLCertificateChainFile /home/elliot/conf/web/magento.mywebsite.ie/ssl/magento.mywebsite.ie.ca <FilesMatch \.php$> SetHandler "proxy:unix:/run/php/php8.1-fpm-magento.mywebsite.ie.sock|fcgi://localhost" </FilesMatch> SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0 IncludeOptional /home/elliot/conf/web/magento.mywebsite.ie/apache2.ssl.conf_* IncludeOptional /etc/apache2/conf.d/*.inc </VirtualHost>
解决方案
问题核心是Apache加载了Magento根目录的.htaccess,但该目录未配置AllowOverride权限,导致RewriteEngine指令被拒绝执行。
修复步骤:
添加Magento根目录的Directory配置
在Apache虚拟主机配置中,新增针对Magento根目录的配置块,设置允许覆盖权限:<Directory /home/elliot/web/magento.mywebsite.ie/public_html/magento2> AllowOverride All </Directory>将该配置块放在现有
/pub目录的配置块旁即可。验证配置并重启Apache
- 检查配置语法是否合法:
apache2ctl configtest - 重启Apache服务生效:
systemctl restart apache2
- 检查配置语法是否合法:
补充说明:
Magento需要根目录的.htaccess来处理路由规则和静态资源映射,即便站点DocumentRoot设为pub目录,Apache仍会向上遍历加载父目录的.htaccess文件。给根目录配置AllowOverride All后,即可允许其中的RewriteEngine等指令正常运行,解决500错误。
内容的提问来源于stack exchange,提问作者elliot
相关产品推荐
相关产品推荐

