Regarding rewrite

Valentin V. Bartenev ne at
Sat Jun 23 11:59:20 UTC 2012

On Saturday 23 June 2012 11:00:16 Fasih wrote:
> Hello all
> I have a usecase for a server rewrite, what I essentially want to do
> is have a common domain like serve some contents
> for specific domains like, etc. for some specific
> url pattern.
> For instance:
> should basically be rewritten to
> zone1/asset. Now zone1 has its own server section with /asset
> configured.
> I tried using rewrite module and realized it doesnt seem to handle the
> usecase I have.
> I created a plugin with NGX_HTTP_SERVER_REWRITE_PHASE expecting that
> if I rewrite request.headers_in.server here, nginx would set the
> srv_conf to zone1 and evaluate location config accordingly. But this
> doesnt seem to work either, nginx seems to handle these cases with a
> 301 redirect instead.
> For now I have configured my system to not use and
> instead have which uses the same set of location
> config as however what I failed to understand was, why is
> server rewriting not allowed, or if it is allowed, how do I use it.

Why do you need several different "server" sections, instead of
something like this:

 server {
     location /zone1 {
         # locations for /zone1 here

     location /zone2 {
         # locations for /zone2 here


 wbr, Valentin V. Bartenev

More information about the nginx-devel mailing list