2015-11-30 107 views
1

我如何配置nginx的以mydomain.com重定向到www.mydomain.com只有當URL的第一部分,不包含單詞APINginx的配置重定向

mydomain.com必須重定向到www.mydomain。 COM

mydomain.com/someapi/要求不得重定向到www.mydomain.com

+0

如果你更新你的問題並添加你的'nginx'服務器配置,提供特定的建議將會更容易。 –

+0

@RichardSmith:改變了標題。謝謝 – Prashanth

+0

'location/{return http://www.example.com; }'和'location〜* api {...}'。請參閱http://nginx.org/en/docs/http/ngx_http_core_module.html#location –

回答

0

我可以使用下面的nginx的配置達到了有條件的重定向:

location/{ 
     if ($host = 'example.com') { 
      rewrite ^/(.*)$ http://www.example.com/$1 permanent; 
     } 

} 

location ~ ^/(.*api)/{ 
     #Here I do proxy pass to my app server 
}