Nginx_Quic与WordPress

发布于 2022-01-16  1327 次阅读


是的又是Quic(H3),在最近我在 nginx-quic 发现目前nginx-quic已经支持OpenSSL-quic分支了。
所以 又回来了。顺便彻底排查一下QuicWordPress无法正常使用的原因。

Nginx_Quic + Openssl-Quic

Openssl-quic仓库地址:https://github.com/quictls/openssl/
Nginx_quic仓库地址:https://hg.nginx.org/nginx-quic
注:
Openssl-quic需要perl否则无法编译。因此需要安装perl
Fedora中可以直接使用dnf install perl来进行安装。
其他系统的话可以自行bing一下。

准备工作

mkdir ~/build
cd ~/build
git clone --recursive https://github.com/quictls/openssl
hg clone -b quic https://hg.nginx.org/nginx-quic

编译OpenSSL

cd ~/build/openssl
./config -Wl,-rpath=/root/openssl/build/lib -fPIC --prefix=/root/openssl/build --openssldir=/root/openssl/build
make -j4
make install
ln -s /root/openssl/build/openssl/lib64/libcrypto.so.81.3 /usr/lib
ln -s /root/openssl/build/openssl/lib64/libssl.so.81.3 /usr/lib
ldconfig

编译Nginx_Quic

cd ~/build/nginx-quic
./auto/configure --with-debug --with-http_v3_module         \
                       --with-cc-opt="-I../openssl/build/include" \
                       --with-ld-opt="-L../openssl/build/lib64"
make -j4
make install

配置

可以参考README

解决Quic下WordPress无法正常使用问题

归根结底,其实是因为 在Quic下nginx没有传递http_host给php,即不存在$_SERVER['HTTP_HOST'],在WordPress下这是致命的,原因不明。
所以我们需要手动传递一个HTTP_HOST给php
将以下内容丢到fastcgi.conf中可以暂时解决问题,让WordPress正常运行。

set $flag 0;
if ($server_port = 443){
    set $flag 1;
}
if ($server_port = 80){
    set $flag 1;
}
if ($flag = 1){
    set $httphost $server_name;
}
if ($flag = 0){
    set $httphost $server_name:$server_port;
}
fastcgi_param HTTP_HOST $httphost;