IIS lik URL rewrite and proxy_pass on NGINX

368 views Asked by At

I have server with CORS problems which causes a lot of pain during development phase. Previously while I was using windows it was quite easy with IIS rewrite module. Something like;

  <rules>
     <rule name="ReverseProxyInboundRule3" stopProcessing="true">
         <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTP_URL}" pattern="^.*(pattern1|pattern2|pattern3|pattern4).*$" />
            </conditions>
            <action type="Rewrite" url="https://example.com/{R:1}" logRewrittenUrl="true" />
     </rule>
  </rules>

so say the call in my environment is;

localhost:8080/folder1/folder2/folder3/pattern1?param1=val1&param2=val2&param3=val3

request is sent to

https://example.com/pattern1?param1=val1&param2=val2&param3=val3

I tried some basic rewrite tricks but unfortunately could not make it work, and not that experinced on nginx's rewrite syntax.

1

There are 1 answers

0
Olgun Kaya On

After some trial (some is an optimistic choice of word) I found how to do what I am looking for.

  rewrite ^.*(/pattern1/.*)$ $1 last;
  location /pattern1 {
      proxy_pass         https://example.com;
  }

Be carefull that there is no trailing slash either on location block or proxy_pass directive. Also the keyword last used at the end of the rewrite directive since I am doing it out of location block