php - 为什么 Apache 打印我的 PHP 文件的内容而不是将它们传递给 PHP-FPM?

标签 php apache

我在 sites-enabled 下有以下配置文件。我正在使用 mod_proxy_fcgi

ServerName local.dev

<Directory /var/www/local/>
    AllowOverride all
    Require all granted
</Directory>


<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerAlias *.local.*.com
    SetEnv CURRENT_ENVIRONMENT ENV_DOCKER

    ServerAdmin webmaster@localhost
    VirtualDocumentRoot /var/www/local/%3/trunk/%3+-%1/site/www

    ProxyPassMatch "^/var/www/local/(.*/trunk/.*/site/www/.*\.php.*)$" "fcgi://php:9000/var/www/local/$1"

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    LogLevel debug

    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerAlias local.*.com
    SetEnv CURRENT_ENVIRONMENT ENV_DOCKER

    ServerAdmin webmaster@localhost
    VirtualDocumentRoot /var/www/local/%2/trunk/%2+/site/www

    ProxyPassMatch "^/var/www/local/(.*/trunk/.*/site/www/.*\.php.*)$" "fcgi://php:9000/var/www/local/$1"

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    LogLevel debug

    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

最佳答案

事实证明,我只需要在我的 Apache 配置中添加一个 SetHandler 指令。

<FilesMatch "\.php$">
    SetHandler "proxy:fcgi://php:9000"
</FilesMatch>

关于php - 为什么 Apache 打印我的 PHP 文件的内容而不是将它们传递给 PHP-FPM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38417067/

相关文章:

Php:使用日历值从数据库中获取记录

php - Symfony 3 PhpUnit 提交表单

linux - 将已编译的 C++ 程序作为 CGI 运行

ruby-on-rails - nginx 用 Passenger 重写规则

php - mysql 查询不起作用

php - 将具有特定值的数组元素移动到数组顶部

php - 在 PHP 中使用复选框删除 MySQL 记录

sql - 如何在现有 Hbase 表上创建 Phoenix 表/ View

PHP代码没有被执行,但是代码显示在浏览器源代码中

php - 长请求会阻止 Apache 和 PHP 中的其他请求