Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx rewrite rule with proxy pass

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 ?

like image 999
Eazy Avatar asked Nov 24 '12 07:11

Eazy


People also ask

How do I rewrite rules in NGINX?

The syntax of rewrite directive is: rewrite regex replacement-url [flag]; regex: The PCRE based regular expression that will be used to match against incoming request URI. replacement-url: If the regular expression matches against the requested URI then the replacement string is used to change the requested URI.

Does proxy change URL?

These proxy servers change the URLs in web pages so that requests for web pages from licensed databases are routed back to the proxy server.

What is return 301 in NGINX?

Temporary and Permanent Nginx Redirect Explained To map this change, the redirects response code 301 is used for designating the permanent movement of a page. These kinds of redirects are helpful when the user wants to change the domain name and no longer wants a browser to access it.


2 Answers

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; 
like image 75
sureshvv Avatar answered Sep 16 '22 14:09

sureshvv


You're missing a trailing slash:

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

This will work without a rewrite.

like image 20
Menasheh Avatar answered Sep 16 '22 14:09

Menasheh