32

I'm trying to implement nginx rewrite rules for the following situation

Request:

http://192.168.64.76/Shep.ElicenseWeb/Public/OutputDocuments.ashx?uinz=12009718&iinbin=860610350635 

Should be redirected to:

http://localhost:82/Public/OutputDocuments.ashx?uinz=12009718&iinbin=860610350635 

I tried this with no luck:

location /Shep.ElicenseWeb/ {
    rewrite ^/Shep.ElicenseWeb/ /$1 last;
    proxy_pass http://localhost:82;
}

What is the correct way to perform such a rewrite for nginx ?

Eazy
  • 3,212
  • 5
  • 24
  • 40

2 Answers2

51

Your rewrite statement is wrong.

The $1 on the right refers to a group (indicated by paratheses) in the matching section.

Try:

rewrite  ^/Shep.ElicenseWeb/(.*)  /$1 break;
sureshvv
  • 4,234
  • 1
  • 26
  • 32
  • you can try it: > location / { rewrite ^/(.*) /Shep.ElicenseWeb/$1 break; proxy_pass http://127.0.0.1:82; } – biolinh Aug 21 '14 at 07:38
8

You're missing a trailing slash:

location /Shep.ElicenseWeb/ {
    proxy_pass http://localhost:82/;
}

This will work without a rewrite.

Menasheh
  • 3,560
  • 3
  • 33
  • 48