【发布时间】:2022-01-13 10:04:58
【问题描述】:
我目前正在尝试在配置如下的 nginx 代理后面设置 WordPress:
server {
listen 80 default_server;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
client_max_body_size 200M;
proxy_redirect off;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $http_host;
proxy_set_header Accept-Encoding "";
proxy_pass http://a2a4d2d0a77264312bfd46b264cba9c8f-wordpress/;
sub_filter_once off;
sub_filter_types *;
sub_filter_last_modified off;
sub_filter '<domain-1>' '$host';
sub_filter '<domain-2>' '$host';
}
}
此代理配置为服务两个域和 受密码保护 (http_auth) 而不是(domain-1 是外部 uri,domain-2 是内部的) 为了做到这一点,我 sub_filter 调用的 uri 以允许内部调用资源而不使用 http_auth 但 WordPress 不断将我 (301) 重定向到 domain-1,这是 WordPress 配置中的 website_URL 和主页设置
如何避免这种情况?如何让 WordPress 在不重定向用户的情况下为两个不同的域提供服务?
卷曲 https:/// -vv :
* Trying XXX.XXX.XXX.XXX:443...
* Connected to <domain-2> (XXX.XXX.XXX.XXX) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=<domain-2>
* start date: Jan 4 16:50:48 2022 GMT
* expire date: Apr 4 16:50:47 2022 GMT
* subjectAltName: host "<domain-2>" matched cert's "<domain-2>"
* issuer: C=US; O=Let's Encrypt; CN=R3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55ff559cca60)
> GET / HTTP/2
> Host: <domain-2>
> user-agent: curl/7.74.0
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 301
< content-type: text/html; charset=UTF-8
< date: Wed, 12 Jan 2022 13:07:09 GMT
< location: https://<domain-1>/
< server: Unknow
< x-powered-by: PHP/7.4.27
< x-redirect-by: WordPress
< content-length: 0
<
* Connection #0 to host <domain-2> left intact
【问题讨论】: