M
M
Mikhail Osher2015-07-16 21:16:47
Nginx
Mikhail Osher, 2015-07-16 21:16:47

Is it possible to forward requests to nginx?

Let's say a certain server knocks on my address:
POST example.com/controller/action + json request body
I want to take the same request and forward it to another domain on the same VPS.
POST staging.example.com/controller/action + same request body
Now I have written a crutch that sends a request via curl.
The question is, can this be done in a more elegant way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-07-16
@miraage

distinctplace.com/infrastructure/2013/10/14/intern...

server
{
  listen 80; 
  server_name a.com b.com c.com;

  location ~* ^/comment/(.*) {
    proxy_set_header HOST shared.com;
    # $1 - stores capture from the location on top
    # $is_args will return ? if there are query params
    # $args stores query params
    proxy_pass http://comment/$1$is_args$args;
  }

}

server {
  listen 80;
  server shared.com;

  location / {
    # Proxy to some app handler
  }
}

upstream comment {
  server localhost; # or any other host essentially
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question