我有一个子域,something.site.com。 在我的主网站site.com/something,我想重写something.site.com,但保持urlsite.com/something完好无损。
那我能用nginx重写规则做些什么?
从文档引用我不认为这是可能的:
If the replacement string begins with http:// then the client will be redirected, and any further rewrite directives are terminated.
你将需要考虑做一个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. # eg: rewrite ^/(abc) /def last; proxy_pass http://something.site.com; # Proxy on the request, without redirecting. } }