我正在努力解决为什么加载.php文件时,我的.htaccess没有被考虑。 下面的文件坐在我的本地主机的webroot。
的.htaccess
# Cause a HTTP 500 test
file.html
<html><body><h1>This should not show</h1></body></html>
file.php
<html><body><h1>This should not show</h1></body></html>
当我访问/index.html时,我得到预期的HTTP500当我访问/index.php时,html显示。
任何想法为什么.htaccess不会加载的PHP文件?
Apache 2.4.6 VHost(/etc/httpd/vhosts.d/website.local.conf):
<VirtualHost *:443> ServerName website.local ServerAlias www.website.local DocumentRoot /var/www/vhosts/website/website <Directory /var/www/vhosts/website/website> require all granted Options Indexes FollowSymLinks AllowOverride All </Directory> # Trigger PHP-FPM to run PHP execution <IfModule proxy_fcgi_module> ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/www/vhosts/website/php-fpm.sock|fcgi://website/var/www/vhosts/website/website" DirectoryIndex index.php </IfModule> SSLEngine on SSLCertificateKeyFile /var/www/ssl/website.key SSLCertificateFile /var/www/ssl/website.crt </VirtualHost>
这个网站没有其他的虚拟主机configuration:
[root@localhost ~]# cat /etc/httpd/conf/*.conf | grep website.local [root@localhost ~]# cat /etc/httpd/vhosts.d/*.conf | grep website.local ServerName website.local ServerAlias www.website.local [root@localhost ~]#
更新1:
我已启用重写:trace3 loglevel遵循https://stackoverflow.com/questions/5641618/how-to-enable-loglevel-debug-on-apache2-server中的.htaccessdebugging指令。 看起来Apache加载PHP文件时,甚至没有考虑.htaccess文件:
访问“/file.html” – .HTAccess被加载,HTTP500按预期返回
==> /var/log/httpd/website-error_log <== [Thu Jul 07 09:36:02.651091 2016] [core:alert] [pid 2822] [client 10.128.3.189:56406] /var/www/vhosts/website/website/.htaccess: Invalid command 'test', perhaps misspelled or defined by a module not included in the server configuration ==> /var/log/httpd/website-access_log <== 10.128.3.189 - - [07/Jul/2016:09:36:02 +0100] "GET /wp-admin/ HTTP/1.1" 500 527 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
访问“file.php” – .HTAccess未加载,并返回HTTP200
==> /var/log/httpd/website-access_log <== 10.128.3.189 - - [07/Jul/2016:09:38:41 +0100] "GET /file.php HTTP/1.1" 200 64057 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0" 10.128.3.189 - - [07/Jul/2016:09:38:41 +0100] "GET /file.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2524 "https://www.website.local/file.php" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0" 10.128.3.189 - - [07/Jul/2016:09:38:41 +0100] "GET /file.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2146 "https://www.website.local/file.php" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
访问“file.jpg” – .HTAccess被加载,HTTP500按预期返回
==> /var/log/httpd/website-error_log <== [Thu Jul 07 09:43:08.403263 2016] [core:alert] [pid 2827] [client 10.128.3.189:56551] /var/www/vhosts/website/website/.htaccess: Invalid command 'sfdgsaga', perhaps misspelled or defined by a module not included in the server configuration ==> /var/log/httpd/website-access_log <== 10.128.3.189 - - [07/Jul/2016:09:43:08 +0100] "GET /file.jpg HTTP/1.1" 500 527 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
我不知道任何configuration将不允许具体的文件/ MIMEtypes的.htaccess ..可能是在哪个顺序模块加载的问题?
更新2:清理上面的虚拟主机文件
更新3:仅在configuration了PHP-FPM时出现问题从configuration中删除下面的代码不再跳过.htaccess文件
<IfModule proxy_fcgi_module> ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/www/vhosts/website/php-fpm.sock|fcgi://website/var/www/vhosts/website/website" DirectoryIndex index.php </IfModule>
更新4:荣誉@ w3d指出这一点。 内部代理请求将跳过.htaccess文件 。 当然是的。 我已经更新了我的VHost文件到下面,从这个线程的答案: Apache 2.4 + PHP-FPM + ProxyPassMatch
<VirtualHost *:443> ServerName website.local ServerAlias www.website.local DocumentRoot /var/www/vhosts/website/website <Directory /var/www/vhosts/website/website> require all granted Options Indexes FollowSymLinks AllowOverride All </Directory> ErrorLog "logs/website-error_log" CustomLog "logs/website-access_log" combined env=!forwarded CustomLog "logs/website-access_log" proxy env=forwarded # Proxy set-up as per # https://serverfault.com/questions/450628/apache-2-4-php-fpm-proxypassmatch # This is to forward all PHP to php-fpm. <FilesMatch \.php$> SetHandler "proxy:unix:/var/www/vhosts/website/php-fpm.sock|fcgi://website/" </FilesMatch> # Set some proxy properties (the string "unique-domain-name-string" should match # the one set in the FilesMatch directive. <Proxy fcgi://website> ProxySet connectiontimeout=5 timeout=240 </Proxy> DirectoryIndex /index.php index.php # If the php file doesn't exist, disable the proxy handler. # This will allow .htaccess rewrite rules to work and # the client will see the default 404 page of Apache RewriteCond %{REQUEST_FILENAME} \.php$ RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f RewriteRule (.*) - [H=text/html] SSLEngine on SSLCertificateKeyFile /var/www/ssl/website.key SSLCertificateFile /var/www/ssl/website.crt </VirtualHost>
这部分虚拟主机configuration是相关的,当你访问该网站的HTTPS,你应该有另一个虚拟主机的实例,你可以再看看,并更新您的post?
荣誉@ w3d指出这一点。 内部代理请求将跳过.htaccess文件。 当然是的。 我已经更新了我的VHost文件到下面,从这个线程的答案: Apache 2.4 + PHP-FPM + ProxyPassMatch