Welcome! Log In Create A New Profile

Advanced

How to combine proxy pass with rewrite?

Posted by AlexLuya 
How to combine proxy pass with rewrite?
October 27, 2011 08:23AM
I want to all requests that target at urls with string "serive" can be redirect to another server that run at different port:8080,for example:
....................................................................................................................................................................................................................
http://localhost/service/image-----------------> http://localhost:8080/service/image

http://localhost/service/image/upload------> http://localhost:8080/service/image/upload

http://localhost/service/blog---------------------> http://localhost:8080/service/blog .................................................................................................................................................................................................................... but blow will still served by ngnix,cause no "service" included within url

http://localhost/wiki/....

http://localhost/video/....

and I have tried:
.................................................................................................................................................................................................................... location / {
root /media/Backup/jetty/webapps;
index index.html index.htm;
if ($request_uri ~* ^/service/.*) {
rewrite ^/service/(.*)$ /$1 permanent;
proxy_pass http://localhost:8080;
}
}
but got error:301 Moved Permanently
can any body tell how to solve this problem?
Thanks
Re: How to combine proxy pass with rewrite?
November 09, 2011 02:53AM
In my opinion you shouldn't use the keywords "permanent" (301) or "redirect" (302) to rewrite internaly.

T.



Edited 1 time(s). Last edit at 11/09/2011 02:53AM by TitusX.
Re: How to combine proxy pass with rewrite?
November 13, 2011 02:10AM
thanks,
I removed "permanent",same result
Re: How to combine proxy pass with rewrite?
November 13, 2011 09:00AM
upstream apache {
server 127.0.0.1:8080;
}

# in your server block:

server{

# location matching is prioritized by accuracy and order of definition

location ~* ^/service/(.*)$
{
proxy_pass http://apache/$1;
proxy_redirect off;
}
}
-------------------------------------------------------------------------------
Above snippet works



Edited 1 time(s). Last edit at 11/13/2011 09:01AM by AlexLuya.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 181
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