Charnjeet Singh
Charnjeet Singh

Reputation: 3107

How to add postfix url with proxy_pass nginx server

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.

Upvotes: 2

Views: 2242

Answers (1)

Richard Smith
Richard Smith

Reputation: 49722

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.

Upvotes: 1

Related Questions