Welcome! Log In Create A New Profile

Advanced

Re: Is there any way to redirect request to another server conf?

Vladimir Shebordaev
June 12, 2012 11:02AM
Hi!

2012/6/12 Thomas <sunyxing@gmail.com>:
>> On 12 Jun 2012 13h29 CEST, sunyxing at gmail.com wrote:
>>
>> > Hi All,
>> >
>> > I'm trying to use nginx as a proxy server which can judge server
>> > name by url.
>> >
>> > e.g.
>> >
>> > server {
>> > listen 80 default_server;
>> > my_rewrite_directive;
>> > }
>> >
>> > server {
>> > server_name a.com;
>> > root html/a;
>> > }
>> >
>> > server {
>> > server_name b.com;
>> > root html/b;
>> > }
>> >
>> > then  GET /a.com/index.html  will be redirected to server a.com;
>>
>> Doesn't this do what you need?
>>
>> server {
>>    listen 80 default_server;
>>
>>    location /a.com/index.html {
>>        return 302 http://a.com$request_uri;
>>    }
>>
>>    location /b.com/index.html {
>>        return 302 http://b.com$request_uri;
>>    }
>> }
>>
>> --- appa
>>
>
> Thanks for advice. Since my servers are supposed to handle the request
>  directly and independently,  302/301 are not acceptable in this
> situation.
>

It seems, you need some kind of reverse proxy setup where nginx is
running as a frontend server. If you do I would suggest to add
something like this to your nginx frontend configuration

location ~ ^/([ab]\.com)/(.*)$ {
proxy_pass http://$1/$2;
proxy_redirect http://$proxy_host:$proxy_port/ /$1/;
}

or more elaborated one based on your backend locations. You'll
probably also need to add certain rules to handle cookies and other
headers also depending on your particular backends. Please refer to
proxy module documentation for details.

In the hope it helps.

Regards,
Vladimir

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Is there any way to redirect request to another server conf?

Thomas 1275 June 12, 2012 09:40AM

Re: Is there any way to redirect request to another server conf?

António P. P. Almeida 390 June 12, 2012 09:48AM

Re: Is there any way to redirect request to another server conf?

Vladimir Shebordaev 419 June 12, 2012 11:02AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 308
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready