首先感谢两位的热心回复,互联网因有你们这样的一群人而多姿多彩。
两位所说的都是伪静态(url重写)的设置方法,可能我上面没有表述清楚哈,
讲下问题吧:
我的情况是 Apache 使用的 php的php-fpm模式也就是开启了mod_proxy 和 mod_proxy_fcgi,php是独立的服务。不是把php当Apache模块使用(mod_php),
而且我配置的伪静态是成功的,因为除了首页,其它分页都是伪静态地址了,只是变成 html 地址后不能正常显示了,显示为php的源代码。
在mod_php 模式下 一切都正常,包括伪静态。
php-fpm 模式配置我是参考网上教程,有条指令是需要将 .php 传递给 fcgi
ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9000/usr/local/apache2/htdocs/$1"
因为伪静态 显示源代码的问题,我这几天翻边了网络 头都大了,度娘各种爬,心想要是再搞不定,还是老老实实的用mod_php模式得了。而然心又不甘。
后来找了一个哥们给的梯子,Google了一下问题。看了一老外写的博客,大致意思是说ProxyPassMatch 指令会忽略别名 和 伪静态设置。
I got to scratch my head on this one for a while. If you're writing a PHP-FPM config for Apache 2.4, don't use the ProxyPassMatch directive to pass PHP requests to your FPM daemon.
This will cause you headaches:
# don't
<IfModule mod_proxy.c>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/
</IfModule>
You will much rather want to use a FilesMatch block and refer those requests to a SetHandler that passes everything to PHP.
# do this instead
# Use SetHandler on Apache 2.4 to pass requests to PHP-PFM
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
Why is this? Because the ProxyPassMatch directives are evaluated first, before the FilesMatch configuration is being run.
That means if you use ProxyPassMatch, you can't deny/allow access to PHP files and can't manipulate your PHP requests in any way anymore.
So for passing PHP requests to an FPM daemon, you'd want to use FilesMatch + SetHandler, not ProxyPassMatch.
Using ProxyPassMatch meant that Alias wouldn’t work, RewriteRules were ignored etc etc.
最后改用
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>
问题解决了。
|