我有一个子域名,something.site.com。在我的主站点 site.com/something 中,我想重写为 something.site.com,但保持 URL site.com/something 不变。
我可以用 nginx 重写规则来做这件事吗?
答案1
引用文档的话我不认为这是不可能的:
If the replacement string begins with http:// then the client will be redirected, and any further rewrite directives are terminated.
答案2
您需要考虑执行 proxy_pass 而不是重写。
例如:
server {
server_name site.com
location /something {
# you may use rewrites here to re-format the path portion of the
# URL before passing it on.
# e.g.: rewrite ^/(abc) /def last;
proxy_pass http://something.site.com; # Proxy on the request, without redirecting.
}
}