0

I have my nginx running in 8080 port and it has only my html's and javascript files and I have another webserver in 8000 port which basically is a json rest server. In my nginx.conf file (in 8080 port) i have something like this:

location /xyz {
   proxy_pass http://localhost:8000;
}

So when the user browser requests something in /xyz path nginx pass request to my server as expected. Now what I would like to do is when the server returns the http_response redirect that response to another url. Is that possible to do?

user1126167
  • 702
  • 2
  • 6
  • 11

1 Answers1

0

Yes. Add the redirect in the port 8000 json rest server and it will redirect the user to the url you want them to go to.

Update:

You can also return a redirect from the REST server. For example:

location / {
    return 302 http://myotherserver.com;
}

Stops processing and returns the specified code to a client. The non-standard code 444 closes a connection without sending a response header.

syntax:     return code [text];
            return code URL;
            return URL;
default:    —
context:    server, location, if

Source: http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return

Tan Hong Tat
  • 6,671
  • 2
  • 27
  • 25
  • Ok, but in the nginx with my web application there's no way to do it? – user1126167 May 23 '14 at 12:56
  • Yes. Simply use the `return` directive. Please see the updated answer. – Tan Hong Tat May 23 '14 at 13:48
  • Well, that return directive didn't work here along with the proxy_pass, because my idea was to do something like this: `location / { proxy_pass http://myrestserver.com; return 302 http://frontendserver.com/some_page.html; }` So after some research I found that what i want to do works with this approach: `location / { post_action @post; return 302 http://frontendserver.com/some_page.html; }` `location @post { proxy_pass http://myrestserver.com; }` But even this approach has the problem that the response cookies are not redirected to the frontendserver. – user1126167 May 27 '14 at 23:26