PHP 仅在 Apache 中不呈现单个别名

标签 php linux apache

我在 httpd.conf 文件的末尾设置了以下别名,但得到了一些意想不到的结果

Alias /simplesaml /var/simplesamlphp/www
<Directory /var/simplesamlphp/www/>
    Require all granted
    AddType application/x-httpd-php .php
    AddHandler application/x-httpd-php .php
</Directory>

当导航到 URL/simplesaml 时,页面加载为白屏,当查看源代码时,页面包含 PHP 代码。这不会发生在服务器上正确呈现 PHP 文件的任何其他站点上。

我可以看到服务器正在获取别名,因为删除了

Require all granted

行,导致 403 禁止错误。删除 AddType/AddHandler 行会导致浏览器下载 PHP 文件。


更新:11/09/17

我通过向我们的托管公司提出支持票得到了以下回应

I did a quick test on one of our test servers and copied over the same configuration file, just setting up a simple index.php inside of /var/simplesamlphp/www and was able to replicate the issue by creating the alias. I suspect that this is related to the change in PHP handlers from CentOS 5/6 to 7 and may require a syntax update in the configuration file. I don't know confidently off hand but I'll dig into this a bit more for you to provide you with more information and hopefully we'll get you on the right track!

几个小时后我收到了这个回复

We were able to resolve the issue of "somethingbig.co.uk/simplesaml" being downloaded when you visit the URL in a browser. We resolved the issue by adjusting your httpd.conf file. The lines below were added and Apache was restarted.

<Files ~ (\.php$)>
SetHandler proxy:unix:/var/www/vhosts/system/somethingbig.co.uk/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>

但是,这实际上根本没有解决任何问题,我现在收到“未指定输入文件”。错误,当我将“index.php”添加到 URL 末尾时,文件仍在下载。


更新 2:11/09/17

以上确实解决了问题,错误日志显示顶级域不允许访问该 base_dir,更新后一切正常。

最佳答案

在 Centos 7 中,需要将以下代码添加到您的 httpd.conf 文件中以允许别名正常运行

<Files ~ (\.php$)>
    SetHandler proxy:unix:/var/www/vhosts/system/[domain]/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>

将 [domain] 替换为您自己的别名域。

关于PHP 仅在 Apache 中不呈现单个别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157237/

相关文章:

php - 使用 PHP 拆分 mySQL 查询结果

php - LoadModule 有两个参数,一个模块名称和一个共享对象文件的名称来加载它

php - Doctrine2 基础;代理、存储库

linux - 如何使用 nc 监听多个 tcp 连接

linux - 将 2 个 csv 文件连接到第三个文件中,并使用 "|"作为分隔符

java - Apache 和 J2EE 共享安全领域/登录、单点登录

php - Yii2 Rest - 自定义操作和 OPTIONS 方法

linux - Linux 服务器上的 Tomcat 未在端口 80 上运行

php - UTF-8贯穿始终

使用 Apache Zoo Keeper 读取 Zoo.cfg 的 Java 类