我在不同的 nginx(1.15.0) 服务器上有两个域(server1 example.com和server2 example.net)。我尝试使用ngx_http_substitutions_filter_module将server2设置为反向代理,但它没有按预期工作。由于我的配置,subs_filter指令应该将example.com替换为example.net但是当我在浏览器中键入example.net时,它会将我重定向到example.com。
nginx.conf
http {
//other settings
.....
include /etc/nginx/sites-enabled/*;
upstream example.com {
server example.com;
}
}
例子.net.conf
server {
listen 80;
server_name example.net www.example.net;
rewrite ^/(.*)$ https://example.net/$1 permanent;
}
server {
listen 443 ssl;
server_name example.net;
ssl_certificate /etc/letsencrypt/live/example.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
root html;
try_files $uri @example.com;
}
location @example.com {
include replace.conf;
proxy_pass http://example.com;
proxy_cookie_domain example.com example.net;
proxy_set_header Accept-Encoding "";
proxy_set_header Host example.com;
proxy_redirect http://example.com http://example.net;
}
}
替换.conf
# replace direct links
subs_filter "www.example.com" "example.net" gi;
subs_filter "example.com" "example.net" gi;
似乎 nginx 忽略了subs_filter指令。有人可以解释一下如何使用 ngx_http_substitutions_filter_module 正确替换 uri 吗?谢谢你的建议!