英语不是我的母语,请原谅打字错误。
我按如下方式配置 Apache 反向代理,它可以正常工作。
ProxyRequests Off
SSLEngine On
SSLProxyEngine On
ProxyPass / https://example.com/
ProxyPassReverse / https://example.com/
而且我的网站(PHP)支持
HTTP/2
,所以我想通过HTTP/2
来代理它。
我启用了
mod_proxy
、mod_proxy_http
、mod_ssl
、mod_http2
、mod_proxy_http2
和其他一些模块。并将 .php
MIME-type 设置为 application/x-httpd-php
。
AddType application/x-httpd-php .php
虚拟主机如下:
<VirtualHost *:443>
DocumentRoot "/path/to/wwwroot/"
ServerName localhost:443
ProxyRequests Off
SSLEngine On
SSLProxyEngine On
ProxyPass / h2://example.com/
ProxyPassReverse / https://example.com/
# Cert
SSLCertificateFile ...
SSLCertificateKeyFile ...
</VirtualHost>
不同的是
ProxyPass / https://example.com/
到 ProxyPass / h2://example.com/
。
浏览器中的响应标头
Content-Type
始终获取默认的 MIME 类型。
你可以在phpMyAdmin Demo找到示例,在DevTools中过滤
whitelist.php
,这个文件Content-Type
是text/javascript
。
通过
HTTP/2
代理它,Content-Type
变成 application/x-httpd-php
,它失去了源 MIME 类型 text/javascript
。
并通过
HTTP/1.1
代理它,效果很好。
我该如何解决这个问题?
谢谢你。
虚拟主机文件配置:
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
ssl_certificate .....
ssl_certificate_key ..........
ProxyRequests Off Order deny, allow Allow from all
<Location />
ProxyPass http://example.com:8000/
ProxyPassReverse http://example.com:8000/
</Location>
</VirtualHost>
接下来我们需要启用一些 Apache 模块。为此,请发出以下命令:
sudo a2enmod 代理
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
Apache 现在需要使用以下命令重新启动:
sudo 服务 apache2 重新启动