我一直在升级/更新的服务器有使用 php 和 python 的页面。我使用 Flask 框架重写了基于 python 的页面,并使用 wsgi 配置了 apache:
<VirtualHost *:443>
ServerName my_fake_site
...
AliasMatch ^\/((?:flask_dir1|flask_dir2).*)\.((css|php|png)$((?:\?.*)?)) /var/www/html/app/$1.$2
AliasMatch ^\/(.*)\.(css|html|php|png) /var/www/html/$1.$2
WSGIDaemonProcess main_proc processes=8 python-home=/var/www/html/venv
WSGIScriptAlias / /var/www/html/wsgi.py
<Directory /var/www/html/>
WSGIProcessGroup main_proc
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
SSLEngine on
...
</VirtualHost>
WSGIPythonPath /var/www/html
WSGIPythonHome /var/www/html/venv
在旧服务器上,指向目录的 url 默认为 index.php 使用 DirectoryIndex 选项(在另一个conf文件中设置)。在新服务器上,我在错误日志中收到“内部服务器错误”消息和 500 响应代码。
所以最终的问题是,如何配置 apache 来同时服务由 php 处理的页面和由 python 处理的页面? (注:flask目录下有几个php处理的页面)
编辑:我添加了另一个 AliasMatch 行,似乎可以执行我想要的操作。我还能够从第二个 AliasMatch 行中删除“php”:
AliasMatch ^\/((?:flask_dir1|flask_dir2).*)\.((css|php|png)$((?:\?.*)?)) /var/www/html/app/$1.$2 AliasMatch ^\/(.*)\.(css|html|png) /var/www/html/$1.$2 AliasMatch ^\/((?:php_dir1|php_dir2).*) /var/www/html/$1
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
As mentioned in my edit, the
AliasMatchdirective worked. From the documentation, this allows Apache to host static files, which I guess also includes php files.