2

I am new to nginx server. I have want to send my request of

http://localhost:81/app/get/all

to

http://localhost:9000/abc/get/all

I have using location regex. But it not working can any one help me.

I have add server as:

 upstream dev {
        server 127.0.0.1:9000;
    }
server {
        rewrite_log on;
        listen [::]:81;
        server_name localhost;

        location / {
            root   path;
        index  index.html index.htm;
    }
    location ~ ^/app/.+ {
        proxy_pass  http://dev;
            proxy_set_header  Host $http_host;
    }
}

Please help me.

Charnjeet Singh
  • 3,056
  • 6
  • 35
  • 65

1 Answers1

1

If you can specify the location as a prefix location, you can use the proxy_pass directive to modify the URI:

location /app/ {
    proxy_pass http://dev/abc/;
    ...
}

See this document for details.

Alternatively, you can rewrite the URI using the break modifier:

location ~ ^/app/. {
    rewrite ^/app(.*)$ /abc$1 break;
    proxy_pass http://dev;
    ...
}

See this document for details.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81