【发布时间】:2018-06-22 10:23:38
【问题描述】:
我在不同的 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;
}
}
example.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;
}
}
replace.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 吗?谢谢你的建议!
【问题讨论】:
-
响应中返回的 MIME 类型是什么?
-
响应头返回
text/html
标签: nginx reverse-proxy web-administration