redirect from api.example.com/service/{domain} to other servers

Eli Fish efish at yotpo.com
Tue Apr 9 14:09:28 UTC 2019


We have nginx server that redirect service requests by server_name using
proxy_pass to upstream:

nginx conf:

server {
  server_name requestsproxy-rest.us.example.com;
....
location / {
.....
    proxy_pass http://Requestsproxy-Rest;

and the upstream file:

upstream Requestsproxy-Rest {
  least_conn;
  server 10.1.1.1:29257 max_fails=4 fail_timeout=1s weight=1;

  server 10.1.1.2:21591 max_fails=4 fail_timeout=1s weight=1;

 }

We want to create nginx rewrite rule that will be able to be accessed via "
api.example.com/service/{domain}" and the nginx will forward/redirect the
request to different address by the {service} to the nginx.

for example:

api.example.com/service/{requestsproxy-rest} -->
{requestsproxy-rest}.us.example.com

how do you think we can manage it via nginx configurations?

I try something like:

> location /{(?:[a-zA-Z0-9][a-zA-Z0-9]+$)} {
>       rewrite (.*) $1.example.com;


Thanks in advanced.


-- 

[image: photo]

Eli Fish

Devops Engineer

m: +(972) 50-5781700

e: efish at yotpo.com| Check out the Yotpo blog!
<https://www.yotpo.com/blog/?utm_source=gmail&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20190409/e7d75186/attachment.html>


More information about the nginx-devel mailing list