【发布时间】:2019-02-26 18:43:07
【问题描述】:
我在将一个网站移到另一台服务器后遇到问题。旧的没有使用 php-fpm,新的使用,到目前为止,我在迁移其他网站时没有遇到任何与此相关的问题。
这个问题是它使用奇怪的方式来实现符号链接。查看 .htaccess 中发生了什么:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
index.php 分解 PATH_INFO 以获得所需的参数:
$url_elements = explode('/', $_SERVER['PATH_INFO']);
主页工作正常。不起作用的是所有子页面。我在前面得到 File not found.,并且 AH01071: Got error 'Primary script unknown\n' from php-fpm in the logs.
我的想法是它的发生是因为 php-fpm 获取带有正斜杠的文件名并将其视为路径。
这是 Apache 通过 php-fpm 处理 PHP 文件的配置:
# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module>
# Enable http authorization headers
<IfModule setenvif_module>
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
<FilesMatch ".+\.phps$">
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(ar|p|ps|tml)$">
Require all denied
</FilesMatch>
</IfModule>
</IfModule>
我不能重写这个网站的代码以更好地创建友好的 URL,因为这个网站只是一个用于 SEO 目的的小页面,公司现在不允许在这上面浪费时间。
如果有人能为我提供一个简单的修复这些错误的方法,我会非常高兴。
提前谢谢你!
【问题讨论】:
-
有你的旧
.conf吗?